in reply to Perl 5.8.0 and Attribute::Handlers

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?

Replies are listed 'Best First'.
Uses for Attributes (was:Re: Re: Perl 5.8.0 and Attribute::Handlers)
by Corion (Patriarch) on Jul 24, 2002 at 16:12 UTC

    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
Re: Re: Perl 5.8.0 and Attribute::Handlers
by bronto (Priest) on Jul 24, 2002 at 15:02 UTC

    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) ;
    }