Each subsequent call to the method accesses the sub normally, i.e. through typeglob lookup.

Yes, this is true, however this is going deeper down the slippery slope where the amount of complex code to maintain is far outweighing the benefits of saving some typing. Take for instance, stack traces. Because you assigned an anon sub ref into a typeglob any stack traces will see the name of this method (and any other ones you created with AUTOLOAD) as simple __ANON__, which means you have no way of distinguishing them from one another. While this might not seem like much of an issue to some, it is a small details that would really be helpful when your up against the wall trying to fix a bug in the 11th hour.

Of course, this too is solveable, Ovid had a hack where he assigned a name to the __ANON__ typeglob slot using local I don't recall the details, and there is also Sub::Name on the CPAN. But either way your now depending on an XS module (Sub::Name) or doing some weird and nasty local/typeglob hackery.

That plumbing amounts to writing a proper import() subroutine which calls AUTOLOAD for the inherited fields and exports them to the inheriting class

Yes, but it wouldn't be that simple if you add in multiple inheritance and the possibility of conflicts/diamond inheritance. Also I am not sure how this would work for deeply inherited fields (more then one level away), but perhaps I am just not understanding the solution fully. Again, all might be solvable problems, but now you've gone from "saving myself some tedious typing" to "building my own object system with AUTOLOAD".

But then, you're right, why reinvent the wheel (there are reasons, though) if there are plenty modules out there which handle that.

The single best reason to re-invent the wheel is to do it as a learning tool. I highly recommend the practice, especially if you have other well written versions to learn/steal from. Moose would not exist if it were not for CLOS and more specifically the Art of the MetaObject Protocol book.

-stvn

In reply to Re^4: "Fields" for "Objects" by stvn
in thread "Fields" for "Objects" by zerohero

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.