Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: How Are Attributes Useful?

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


in reply to How Are Attributes Useful?

I've used attributes productively a few times.

In a client server application, I used attributes on methods of the model classes to implement access controls. The syntax was something like :Access( rw ) to mark a method as needing read and write access. The actual server class performed authorization and authentication and knew the permissions of remote users. Before delegating any method call to a model object, it would check the permissions.

I could have done this without attributes, but it seemed like a nice way to keep the metadata (what does this method accomplish) in the same place as the actual code of the method.

In a recent journal entry (Dark, Dark Corners of Perl), I speculated that it's possible to use attributes on methods to simplify declaring and accessing parameters. I'm not ready to demonstrate my proof of concept yet, but I really like how the syntax works. It's nice to be able to manipulate subroutines at the appropriate time without resorting to source filters.

Replies are listed 'Best First'.
Re^2: How Are Attributes Useful?
by Ovid (Cardinal) on Jan 18, 2005 at 22:47 UTC

    chromatic wrote:

    In a recent journal entry (Dark, Dark Corners of Perl), I speculated that it's possible to use attributes on methods to simplify declaring and accessing parameters. I'm not ready to demonstrate my proof of concept yet, but I really like how the syntax works. It's nice to be able to manipulate subroutines at the appropriate time without resorting to source filters.

    I wholeheartedly agree, and between the two, I would use your solution over mine any day of the week if it's feasible, but I have a couple of questions. First, can you do multi-method dispatch with that? I've been porting some Java to Perl and lack of MMD has been a pernicious source of bugs.

    Second, will this run under mod_perl? It's my understand that attributes rely on a CHECK block. That won't get triggered under mod_perl. I know we discussed this the other day, but for the life of me, I can't recall what was said :)

    Cheers,
    Ovid

    New address of my CGI Course.

      I think it'd be very easy to do MMD with this technique. There's one potentially tricky spot, but I think it's doable.

      I also think attributes will run just fine under mod_perl. Maypole uses them, for example, and it works. There are different ways to declare where Attribute::Handlers runs, for example.

      I don't use attributes, so I can't vouch for it either way, but if they don't work under mod_perl, someone should tell the Maypole developers that. It uses sub attributes for security purposes.

Log In?
Username:
Password:

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

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

    No recent polls found