Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Arcane syntax question (Catalyst/OOPerl)

by bitstream (Sexton)
on Feb 06, 2006 at 22:24 UTC ( [id://528357]=perlquestion: print w/replies, xml ) Need Help??

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

Ok, so I've been away from Perl for awhile and have recently been looking at Catalyst. This isn't a Catalyst question, however.
There are a lot of methods that have specifiers of some type in them like this (below):
sub upload : Global { # ... } sub default : Path('/static') { # ... }

Problem is, as familiar with Perl OO as I think I am, I don't think I've ever seen this syntax. So the question is: what's "Global" and "Path" in this case? A source filter at work? Some inheritance-gorp that I'm unaware of?

Replies are listed 'Best First'.
Re: Arcane syntax question (Catalyst/OOPerl)
by Corion (Patriarch) on Feb 06, 2006 at 22:28 UTC

    That syntax declares an attribute. I'm not sure where they are discussed in the Perl documentation - maybe only within the attributes pragma.

    If you want to learn how you can (ab)use attributes yourself, Attributes::Handlers is the best wrapper I guess.

      Excellent. So the attributes can gain knowledge of function invocation before they actually are invoked, and (in this case) potentially intercept/deny/replace them? I think?

      I see where in "perldoc attributes" the syntactic sugar maps the colon syntax into the "use attributes" syntax, though I didn't see an example of actually writing a custom attribute without Attribute::Handlers. This omission is probably ok as I can read the source there.

      I can definitely see AOP-style implications. Or maybe I'm missing the point here?

        Catalyst uses these for metadata about methods. It maps URLs to methods using this data.
Re: Arcane syntax question (Catalyst/OOPerl)
by jbrugger (Parson) on Feb 07, 2006 at 05:48 UTC
    Nice question, i asked it as well before :), so i first wanted to shout someting like "use the super search", or somthing like that...
    Anyway, how can you search for this, if you don't know what to search for, so i'm sorry for that thought :)...
    Anyway, as CountZero explained, Catalyst uses it like following:

    <shameless quoting>
    Catalyst needs those attributes to decide which sub to call when it parses the URL. You can see it working very nicely if you run the included your_app_server.pl script. In its debug-output you see it building your packages and subs linked to the URLs it understands.
    </shameless quoting>

    "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.
Re: Arcane syntax question (Catalyst/OOPerl)
by geekgrrl (Pilgrim) on Feb 07, 2006 at 20:13 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://528357]
Approved by Corion
Front-paged by bart
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2024-04-18 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found