Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How Are Attributes Useful?

by Zaxo (Archbishop)
on Jan 18, 2005 at 22:24 UTC ( [id://423203]=note: print w/replies, xml ) Need Help??


in reply to How Are Attributes Useful?

I recall you have been studying the :lvalue attribute for subs. Reflect that that attribute is more than a tag that you may query at runtime like some kind of metadata. I'm not sure how I'd go about querying that.

When the :lvalue attribute is applied to a sub, it changes how the sub is compiled and what usage is permitted of it.

The description of attributes as tags to be queried sounds a lot like the "properties" Lisp can attach to a symbol. I think that's a mischaracterization.

A read of the Attribute::Handlers pod suggests that magic outside runtime is what attributes are for. Those docs give some non-trivial examples. I suspect that perldoc -m Attribute::Handlers will yield lots of wisdom on the matter, but I know for a fact it won't be easy ;-)

I'm sure that perl attributes would benefit from more of us experimenting with them.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: How Are Attributes Useful?
by Limbic~Region (Chancellor) on Jan 19, 2005 at 00:58 UTC
    Zaxo,
    Reflect that that attribute is more than a tag that you may query at runtime like some kind of metadata. I'm not sure how I'd go about querying that.

    Really. I haven't found a single example of how one might modify the behavior of a subroutine using attributes outside the few built-ins. As far as querying the attributes - it was in the synopsis of perldoc attributes

    use attributes (); # optional, to get subroutine declarations my @attrlist = attributes::get(\&foo);
    I have looked at Attribute::Handlers and still felt unsatisfied. Attribute::Handlers::Prospective looks promising after glancing at the documentation but I find it hard to believe that there are no code examples outside the module. Why is this I wonder. It seems to me that you are right - the majority of us are in the dark and so attributes, if useful at all as others have implied, are way underdeveloped in perl.

    Cheers - L~R

      Check Bot-CPAN. It's Glue module uses Attribute::Handlers to define well.. attributes to methods. That lets you define a bot command like:

      sub list :help ("lists available modules") :private :adminCmd { # implements list() }

      I thought that was a rather elegant way of doing this.

Re^2: How Are Attributes Useful? (just tags)
by tye (Sage) on Jan 18, 2005 at 23:02 UTC

    No, they are just text tags. Perl checks for the "lvalue" tag and, if found, does special processing. But the attribute is just a way to tell Perl to do that special processing.

    - tye        

      That's an implementation detail. The point is that thay represent metadata for the perl compiler, not the user's runtime. It's magic, I say!

      After Compline,
      Zaxo

        s/not/or/

        Attributes are just syntactic sugar for implementation details.

        If you think attributes are the magic, then you'll never understand how to use attributes in general.

        - tye        

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://423203]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-04-18 07:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found