Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

A solid, complete implementation of attributes. Luckily, attributes are marked experimental.

Here's the issues I think need to be addressed, in a fuzzily sorted order of importance.

  • Namespace scoping: This is fundamental. No more attributes in UNIVERSAL. It should be as easy to import/export attributes as variables and subroutines. Without it you can't release any general purpose attribute modules on CPAN that other module authors can re-use. They'll only be useful in-house where you can control they won't conflict with each other. Back in 2005 26 of 28 modules (that I found) on CPAN that provided attributes polluted the UNIVERSAL namespace.
  • A unified implementation: The simple FETCH_/MODIFY_*type*_ATTRIBUTES methods implementation is just begging for trouble. It works for systems like Catalyst, but not as a general language feature.
  • True attribute arguments: my $foo : Foo(foo => 'bar'); should work. The parenthesis shouldn't be a single quote yielding a string ("annotation"), but provide arguments to the implementor.
  • A working way to store attribute metadata: After my $foo : Foo;, how do you know that $foo is decorated with Foo?
  • Better/working subroutine attributes: Subroutine attributes should be able to "redefine" the subroutine. (Currently, named subroutines are not fully defined when MODIFY_CODE_ATTRIBUTES is called.) No more broken INIT workarounds. Anonymous subroutine attributes have no chance at all to modify the subroutine (or return another subroutine, wrapping the original). my $foo = sub :Memoize { ... }; cannot be written.

Some two years ago I wrote a note about why I think the current implementation of attributes is broken. I also wrote about a set of modules that would solve some of the issues. While I believe it was a better implementation than the alternatives it didn't overcome the major obstacles as they require changes in the perl source. So I put that work back on the shelf. In real life this is a "redo and do it right" subject.

I still believe there's a lot of potential in attributes, if only implemented properly.

Update: see Namespaces and importing/exporting of attributes for a concrete idea of a possible improvement.

lodin


In reply to Re: what would you like to see in perl5.12? (attributes) by lodin
in thread what would you like to see in perl5.12? by ysth

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2014-09-22 10:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (188 votes), past polls