A long time delayed, this weekend I finally implemented a solution to the can/AUTOLOAD issues that I thought up at Why breaking can() is acceptable. It is on CPAN as Class::AutoloadCAN.

Now I'm looking for feature suggestions, and ideas for good examples.

There are two feature possibilities that I have thought of.

The first is to provide an easy way to know within CAN what call-level you have to go to to get to the call that asked for the method. This would be useful if, for instance, someone wanted to implement a module that allowed for creating private or protected methods. The only problem is the API. I could set a global variable. But what do I call it? And if I export that then I can't use local to localize it.

The second is some version of NEXT. Of course the built-in SUPER or TheDamian's module won't work because they can only find the AUTOLOADs which are all pretty much the same. I need to have the logic in Class::AutoloadCAN. So I have to decide how to do it. The obvious way is to provide in the AUTOLOAD a "next" method. One question is how I should handle the "dreaded diamond". Do you avoid calling methods in the inherited superclass twice, or do I try to call methods in the inherited superclass twice?

There is a subtle conflict. It is nice that $obj->foo(@args); is always the same as $obj->can("foo")->(@args); but making that true with the next extension that I have proposed means breaking using $this->can("foo") == $that->can("foo") to test if two objects have the same method. I don't think that people would really mind if the latter broke, particularly considering what they get for it, but I'm not a heavy user of UNIVERSAL::can so I don't know how people like to use it. If you care either way then holler.

Now good example ideas. The most obvious one is to implement a class that allows you to do this:

private foo => sub { ... }; protected bar => sub { ... }; # The only reason for this is so that it can call on # private and protected versions of baz in a superclass, # and that requires the "next" functionality that I # thought of. (Guess how I realized that "next" might # be nice to have?) public baz => sub { ... };
Perhaps people would prefer the syntactic sugar of:
private foo { ... } protected bar { ... } public baz { ... }
even though it means using a source filter with the attendant fragility.

I think that people might want this because I've seen people complain of the lack of it in Perl, but I have no idea what a module that provides this should be called. Or what it further features it should have.

Feedback and further suggestions solicited.


In reply to RFC: Class::AutoloadCAN by tilly

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.