bronto has asked for the wisdom of the Perl Monks concerning the following question:

So 5.8.0 is out.

As always, the first document I dig into when a new perl comes out is perldelta. In section New Modules and Pragmata we have:

Attribute::Handlers, originally by Damian Conway and now maintained by Arthur Bergman, allows a class to define attribute handlers. Both variables and routines can have attribute handlers. Handlers can be specific to type (SCALAR, ARRAY, HASH, or CODE), or specific to the exact compilation phase (BEGIN, CHECK, INIT, or END).

Anyway, in the same document, you read:

The my EXPR : ATTRS syntax now applies variable attributes at run-time. (Subroutine and our variables still get attributes applied at compile-time.) Note that the new semantics doesn't work with the Attribute::Handlers module (as of version 0.76).

The question is: how do you read these?

Any drop of wisdom for me?

Ciao!
--bronto

# Another Perl edition of a song:
# The End, by The Beatles
END {
  $you->take($love) eq $you->made($love) ;
}

Replies are listed 'Best First'.
Re: Perl 5.8.0 and Attribute::Handlers
by hakkr (Chaplain) on Jul 24, 2002 at 13:54 UTC
    sub question,
    What are they for and why would you want to use them. Way I am understanding it is you can assign subroutines to a variable. So a variable can have a subroutine associated with it without being blessed into a class. And the subroutine called will be dictated by the type of the variable?

      Attributes are cool whenever out-of-band data is required. Some examples :

      • I have a toy application here, where I use attributes to specify access levels for subroutines.
      • If your application consists of a chain of list-munging subroutines, you can easily add tracking information as which routine touched which item without having to change/adapt every routine and without conflict with the output.
      • The always present compiler hints or runtime type enforcement can also be implemented via attributes (like the :Integer attribute), but of course, this is also out-of-bound information about your "data" (this time, your program is regarded as data by perl)

      perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The $d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider ($c = $d->accept())->get_request(); $c->send_response( new #in the HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web

      What attributes are for? Uhmmmm... why you ask me? The camel book (3rd edition, page 745) shows my num PI : constant = atan2(1,1) * 4 as an example and tells briefly about other possible uses.

      Why would I use them. I came around them in 180455 and replies. Yesterday night I read perldelta, today I was digging into the code and docs of Attribute::Protected. I found it interesting, but since it relies on Attribute::Handlers it would be interesting to know if it is safe to write production code with it.

      attributes reports the usage attribute declaration for variables is still experimental. What I would like to have is, say, a measure of how much experimental attributes are: is it safe to play with them in subroutines now? Is it not? Code that uses Attribute::Handlers is reliable or is expected to break in the short/medium term?

      Ciao!
      --bronto

      # Another Perl edition of a song:
      # The End, by The Beatles
      END {
        $you->take($love) eq $you->made($love) ;
      }

Re: Perl 5.8.0 and Attribute::Handlers
by stefp (Vicar) on Jul 29, 2002 at 21:00 UTC
    $A++, always surfing the bleeding edge of technology demonstrates the use of attributes... and currying to add some condiments.

    Constante usée pour rien Stéphane 8-jui-2002 use constant; my constant $A++ De l'utilisation des attributs Stéphane 8-jui-2002 sub _ : lvalue { $A }; ++_(); D'une autre utilisation des attributs Stéphane 8-jui-2002 use Attribute::Handlers; sub _ : ATTR(SCALAR) { ${$_[2]}++ } my $A : _ ; $A; La cuisine au curry (par Ed) Stéphane 14-jui-2002 use Perl6::Currying; sub add($a, $b) { $a + $b }; $incr = &add.prebind(a=>1); $A = $incr->($A)

    -- stefp -- check out TeXmacs wiki

Re: Perl 5.8.0 and Attribute::Handlers
by imoore (Novice) on Jul 25, 2002 at 06:59 UTC
    I think you are expecting too much as 5.8.0 is the experimental developers release, not the stable release; this inconsistency requires further development to resolve...
      5.8.0 is stable release. Do not confuse it with 5.7.xx and previous 5.8.0 release candidates which are experimental developers releases.

      --
      Ilya Martynov (http://martynov.org/)