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.


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

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.