[Israel.pm] Uses for Attributes

Shlomi Fish shlomif at gmail.com
Tue Mar 20 02:54:17 PDT 2007

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?

> I may miss on something very cool and important for perl programming,
> and the syntax is nice, but what can I do with it ?

I tried to show you some uses for it in my previous message. If we
take the writing a testing library as an example, I can mark the
functions that are directly used for test assertion with the ":
testfunc" attribute and then walk the caller() (
http://perldoc.perl.org/functions/caller.html ) stack backwards to
find the top function with this marker and then display the context
that it has. This beats Test::Builder's current method of doing local
$Test::Builder::Level = $Test::Builder::Level + 2;

And I gave other examples for CPAN modules that make use of attributes.


        Shlomi Fish

 from the doc I
> didn't understand the mechanics (It certainly does not expand on what
> import() does. I tried to read the source for that, but didn't
> understand it either).
> --
> Oded
> ::..
> A verbal contract isn't worth the paper it's written on.
>     -- Samuel Goldwyn
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl

Shlomi Fish http://www.shlomifish.org/

If his programming is anything like his philosophising, he
would find 10 imaginary bugs in the "Hello World" program.

More information about the Perl mailing list