Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is one of those times where it's appropriate to disable strict refs. However, there are a couple of issues that you may wish to be aware of. First, I see a use vars statement right after the opening brace of the AUTOLOAD sub. If you're just putting it there because this is conceptually where you feel it should go, that's probably okay, even though I confess that I prefer my use statements grouped together at the beginning of a program/module. However, I see that many programmers put the use statement in a subroutine thinking that it will delay the use of the module or pragma until needed. If that's what you are doing, you should be aware that use happens at compile time, not run time. Unfortunately, you can't just require in the vars pragma and then pass in an import list as this will kill your program under strict. If you are using 5.6 or later, you can do this:

sub AUTOLOAD { our $AUTOLOAD; ... }

If you're using a prior version, you may as well slap a 'no strict' at the top of the subroutine (yuck). Otherwise, if you expect to be calling AUTOLOAD virtually every run of the program, I'd put the use statement at the top of the package.

No offense, but do you know what the following does?

sub new { # any constructor my ($proto) = shift; my $class = ref($proto) || $proto; my $parent = ref($proto) && $proto; my $self; $self = {}; # create a new object bless($self, $class); } # new

You have created a scalar named $parent, but you don't use it. Further, you're assigning to $class with ref($proto) || $proto. What is your reason for doing the latter? This is typically used if you want to clone an object. This might be appropriate, but rarely is it. I would change your constructor to the following, unless you have a decent justification otherwise:

sub new { # any constructor my $class = shift; my $self = {}; # or some initializing routine bless $self, $class; } # new

Once you get everything working with that, it should be fine. If you need the other functionality later, you can add it in as needed.

Hope this helps.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid - minor code nits) Re: Adding autoloaded methods to symbol table with using strict refs by Ovid
in thread Adding autoloaded methods to symbol table with using strict refs by strat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-19 23:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found