[Edinburgh-pm] Question about using attributes

Robert Rothenberg robrwo at gmail.com
Tue Jun 21 15:30:55 PDT 2011


What if main doesn't use Attr?
On 21 Jun 2011 22:25, "Aaron Crane" <perl at aaroncrane.co.uk> wrote:
> Robert Rothenberg <robrwo at gmail.com> wrote:
>> I am having a strange problem with Attribute::Handlers that looks like
>> some kind of bug:
>> when it's called from a separate package in a separate file, "foo"
>> is not called, although the compiler does accept the ":foo" attribute.
>
> It seems to be working for me, unless I'm misunderstanding the problem:
>
> $ head *
> ==> Attr.pm <==
> package Attr;
> use Attribute::Handlers;
> sub UNIVERSAL::foo :ATTR(CODE) {
> warn "applying foo attribute to ", *{ $_[1] }, "\n";
> }
> 1;
>
> ==> Thing.pm <==
> package Thing;
> sub wobble :foo {}
> 1;
>
> ==> main.pl <==
> use Attr;
> use Thing;
> sub wibble :foo {}
> $ perl main.pl
> applying foo attribute to *Thing::wobble
> applying foo attribute to *main::wibble
> $ perl -MAttribute::Handlers -wE 'say for $^V,
Attribute::Handlers->VERSION'
> v5.12.1
> 0.88
>
> --
> Aaron Crane ** http://aaroncrane.co.uk/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/edinburgh-pm/attachments/20110621/36561042/attachment.html>


More information about the Edinburgh-pm mailing list