For more on the God antipattern see http://en.wikipedia.org/wiki/God_object. It refers to the case when one class or module tries to take on too many jobs at once. This defeats the entire point of modularity, which is to enable code to be broken into modular pieces, each of which has reasonable complexity.

If you do not know what benefits modularity is supposed to bring, or what good modularity looks like, please pick up a book like Code Complete 2. It is a large and important topic, and one I certainly don't have time to go into in any depth today.

Moving on, it sounds like you are micro-optimizing on memory usage. The vast majority of mod_perl sites should just use a reverse proxy in accelerator mode and then not concern themselves overly much with memory needs. See this guide for an overview of what that is, and how to do it. (Yes, it is a 1.0 specific guide. But the advice still applies pretty well to 2.0. BTW I really, really hope you're using pre-fork mode with 2.0...)

That said, I don't know the exact amount of memory needed to have 100 entries in a symbol table, but it is going to be at most a few K. (The functions themselves take up no space because they already exist.) If you are having trouble with running out of memory, this is not where you should look for improvements.

Moving on, the syntax *foo = $coderef; is the standard way to manipulate the package table and install a function. See perlmod for more examples. It is certainly better than the eval solution that you are using in your AUTOLOAD. Better in what way, you ask? Well for a start, if the code you are generating is wrong, then the eval will silently fail and you won't get a good error message. Real example. If one of your constants is supposed to be "Hello, world" then your eval will fail, no error will be reported, and your AUTOLOAD is going to blow up. So compare:

# This might break badly depending on $value eval "sub $AUTOLOAD { $val }"; # This will work no matter what $val happens to be. no strict 'refs'; *$AUTOLOAD = sub { $val };
Which means that this is a piece of syntax you really should learn.

Finally we come to your two questions. Yes, you can replace $AUTOLOAD with $constname if you are in the right package. Secondly the goto will go to the new function you just defined if it was properly created by eval, and it just returns a value. So you can replace one by the other. However as your code currently stands, that goto is the only sign you are given that your code broke if it broke.


In reply to Re^7: Autoloading tie routines by tilly
in thread Autoloading tie routines by cmac

Title:
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, details, 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, summary, 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.