Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: Introspection of Moose/Mouse attributes fails to find native trait with `does`

by stvn (Monsignor)
on Aug 25, 2011 at 12:57 UTC ( #922337=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Introspection of Moose/Mouse attributes fails to find native trait with `does`
in thread Introspection of Moose/Mouse attributes fails to find native trait with `does`

Basically (and perigrin already said this sorta), the OP is introspecting a meta-object, not any kind of prototypical value that would be stored by the attribute. So really, there should be no reason that $attr->does('Bool') using the traditional meaning of does.

Next, the whole traits => ['Bool'] thing needs to be understood. By adding the 'Bool' trait to the attribute you are really just asking Moose to (optionally) provide delegate-able methods (specific in this case to Bool values). So in this particular case you could do the following:

has 'guernsey' => ( traitls => [ 'Bool' ], is => 'rw', isa => 'Bool', handles => { be_a_guersey => 'set', dont_be_a_guernsey => 'unset', } );
Which would then allow the OP to do:
my $cow = MyCow->new; $cow->be_a_guernsey();
and get exactly the same behavior as his old code. Basically the Native Traits are only related to types in that they provide specific sets of behaviors for some native Perl types. And they are only related to roles in that they are implemented as roles that are applied to the attribute meta-object.

So, while I can see that these things can be a little misleading initially. Once you learn what all the pieces are made of, and roughly how they fit together, it should make sense going forward because it is really pretty consistent.

-stvn


Comment on Re^3: Introspection of Moose/Mouse attributes fails to find native trait with `does`
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2014-07-31 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (253 votes), past polls