[Israel.pm] Uses for Attributes

Oded Arbel oded-linux at typo.co.il
Tue Mar 20 04:56:44 PDT 2007



On Tue, 20 Mar 2007 11:54:17 +0200, "Shlomi Fish" <shlomif at gmail.com> wrote:
> Hi Oded!
> 
> On 3/20/07, Oded Arbel <oded-linux at typo.co.il> wrote:
>> On Tue, 2007-03-20 at 00:28 +0200, Shlomi Fish wrote:
>> > Hi all!
>> >
>> > Back on the last Israel.pm meeting I've discussed attributes (
>> > http://perldoc.perl.org/attributes.html ) with Sagiv in the context of
>> > Catalyst.
>>
>> Ok, I've read the doc, and it talks about attributes being a short hand
>> for attributes::->import( sth => sth, sth), but what does that do ?
> 
> Well, attributes associate more data to the function or variable,
> besides its name. So you can query the variable for the data
> associated with it and treat it differently based on it.
> 
> Or are you referring to the implementation details?

No - just what it does. So I understand its just a way to mark subroutines (and variables) with a specific keyword. so I can do something like this:

----
sub myfunc : isverysecret {
  # do something secret
}

manage_callbacks \&myfunc;

sub manage_callbacks {
  shift;
  if (attributes::get $_ == 'isverysecret') { # do something }
}

----

or some such (barring the syntax is probably all wrong), right ?

-- 
Oded




More information about the Perl mailing list