In the docs I see this for Moose::Meta::Attribute
## EXCERPT
get_value
set_value
eval { $point-meta-get_attribute('x')-set_value($point, 'forty-two') };
if($@) {
print Oops: $...@\n;
}
Attribute (x) does not pass the type constraint (Int) with 'forty-two'
Before setting the value, a check is made on the type constraint
of the attribute, if it has one, to see if the value passes it. If the
value fails to pass, the set operation dies with a throw_error.
Any coercion to convert values is done before checking the type constraint.
To check a value against a type constraint before setting it,
fetch the attribute instance using find_attribute_by_name in
Class::MOP::Class, fetch the type_constraint from the attribute using
type_constraint in Moose::Meta::Attribute and call check in
Moose::Meta::TypeConstraint. See Moose::Cookbook::Basics::Recipe4 for
an example.
## END
But, yet get_value doesn't seem to be working.
perl -Moose -e'has q[format_feed]= ( isa = Str, is = ro );
print Class-new-meta-get_attribute(q[format_feed])-get_value()'
You must pass a package name and it cannot be blessed at
/usr/local/lib/perl/5.10.0/Class/MOP/Class.pm line 37
Class::MOP::Class::initialize('Class::MOP::Class', '') called at
/usr/local/lib/perl/5.10.0/Class/MOP/Attribute.pm line 322
Class::MOP::Attribute::get_raw_value('Moose::Meta::Attribute=HASH(0x91c8310)',
undef) called at /usr/local/lib/perl/5.10.0/Class/MOP/Attribute.pm
line 309
Class::MOP::Attribute::get_value('Moose::Meta::Attribute=HASH(0x91c8310)',
undef) called at /usr/local/share/perl/5.10.0/Moose/Meta/Attribute.pm
line 562
Moose::Meta::Attribute::get_value('Moose::Meta::Attribute=HASH(0x91c8310)')
called at -e line 3
I guess it is using Class::MOP::Attribute's get_value which requires a
class name. This is odd, I just want to read from the sucker, in the
source of Mooose::Meta::Attribute I see this return
$self-SUPER::get_value($instance) which seems to imply the instance
is being set, but it isn't working. Any ideas?
--
Evan Carroll
System Lord of the Internets
http://www.evancarroll.com