Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Class::Accessor Problem

by PerlingTheUK (Hermit)
on Nov 27, 2005 at 14:50 UTC ( [id://512023]=perlquestion: print w/replies, xml ) Need Help??

PerlingTheUK has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,
as a self written base class I use for all my objects is growing steadily, I try to focus it a bit more on my specific demands and outsource more common functionality. One of these features is provided by Class::Accessor. Reading the documentation I cannot see where this is difficult to use or where I might make any errors but the following code:
BEGIN{ ... use Class::Accessor; our ( $VERSION, $LAST_ERROR, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS + ); @ISA = qw( Class::Accessor ); ... Variant->mk_accessor( qw(name nodes) ); }
exits on compilation with the following message:
Can't locate object method "mk_accessor" via package "Variant" at Vari +ant.pm line 31.
I wonder if someone with some experience using this class can spot the error as I have spent almost a day on this yet no proper clue what is going wrong.

Cheers,
PerlingTheUK

Replies are listed 'Best First'.
Re: Class::Accessor Problem
by Ovid (Cardinal) on Nov 27, 2005 at 16:53 UTC

    The method is named mk_accessors. You forgot the "s" on the end.

    Cheers,
    Ovid

    New address of my CGI Course.

      OUCH, Thanks :(

      Cheers,
      PerlingTheUK
Re: Class::Accessor Problem
by BrowserUk (Patriarch) on Nov 27, 2005 at 16:09 UTC

    Comment out the BEGIN{} block.

    Update: I re-phrase that. Try taking the failing code out of the BEGIN() block.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      BrowserUK,
      Thanks, but it does not work I tried to remove the line from the BEGIN block and I also completely removed the block. Either option did not make a difference to the error message.
      The actual benchmark script coming with this package is running fine in my environment and I cannot spot my error. The current code - which still produces the above quoted error is:
      package Variant; use strict; use warnings; use Exporter; use Class::Accessor; our ( @EXPORT, @EXPORT_OK, %EXPORT_TAGS ); @EXPORT = qw(); %EXPORT_TAGS= (); @EXPORT_OK = qw(); use base ( qw(Exporter Class::Accessor) ); our ( $VERSION, $LAST_ERROR ); __PACKAGE__->mk_accessor( qw(name nodes) );
      I have noticed, that the benchmark example as well as the examples in the documentation use either a base class with all fields defined or Class::Fields as base class. I intend - and only then does using Class:Accessor make sense to me to include it in a base class that does not yet know which fields are in my derived classes. Are there any issues with this setup? Do I need to define the fields of my class before calling mk_accessor( @fieldnames )

      Cheers,
      PerlingTheUK

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://512023]
Approved by Crackers2
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2024-04-24 16:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found