X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FPurePerl.pm;h=2aa712ecf2e312e0b15b3290867ef43275ee43cb;hp=7e94d87f2fe884faa950a97ffb5443cd4a16ac6c;hb=d503a4f3aa9eda772309f6c99ccd4dfcdfed059d;hpb=d990f7911dfd6a36d1dcc072e7adb72bf0379349 diff --git a/lib/Mouse/PurePerl.pm b/lib/Mouse/PurePerl.pm index 7e94d87..2aa712e 100644 --- a/lib/Mouse/PurePerl.pm +++ b/lib/Mouse/PurePerl.pm @@ -2,8 +2,7 @@ package Mouse::PurePerl; require Mouse::Util; -package - Mouse::Util; +package Mouse::Util; use strict; use warnings; @@ -124,8 +123,7 @@ sub generate_can_predicate_for { return $predicate; } -package - Mouse::Util::TypeConstraints; +package Mouse::Util::TypeConstraints; use Scalar::Util qw(blessed looks_like_number openhandle); @@ -199,8 +197,7 @@ sub _parameterize_Maybe_for { -package - Mouse::Meta::Module; +package Mouse::Meta::Module; sub name { $_[0]->{package} } @@ -236,8 +233,7 @@ sub add_method { return; } -package - Mouse::Meta::Class; +package Mouse::Meta::Class; sub method_metaclass { $_[0]->{method_metaclass} || 'Mouse::Meta::Method' } sub attribute_metaclass { $_[0]->{attribute_metaclass} || 'Mouse::Meta::Attribute' } @@ -327,8 +323,7 @@ sub is_immutable { $_[0]->{is_immutable} } sub __strict_constructor{ $_[0]->{strict_constructor} } -package - Mouse::Meta::Role; +package Mouse::Meta::Role; sub method_metaclass{ $_[0]->{method_metaclass} || 'Mouse::Meta::Role::Method' } @@ -338,8 +333,7 @@ sub is_anon_role{ sub get_roles { $_[0]->{roles} } -package - Mouse::Meta::Attribute; +package Mouse::Meta::Attribute; require Mouse::Meta::Method::Accessor; @@ -453,12 +447,23 @@ sub _process_options{ my $tc; if(exists $args->{isa}){ - $args->{type_constraint} = Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint($args->{isa}); + $tc = $args->{type_constraint} = Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint($args->{isa}); } - elsif(exists $args->{does}){ - $args->{type_constraint} = Mouse::Util::TypeConstraints::find_or_create_does_type_constraint($args->{does}); + + if(exists $args->{does}){ + if(defined $tc){ # both isa and does supplied + my $does_ok = do{ + local $@; + eval{ "$tc"->does($args) }; + }; + if(!$does_ok){ + $class->throw_error("Cannot have both an isa option and a does option because '$tc' does not do '$args->{does}' on attribute ($name)"); + } + } + else { + $tc = $args->{type_constraint} = Mouse::Util::TypeConstraints::find_or_create_does_type_constraint($args->{does}); + } } - $tc = $args->{type_constraint}; if($args->{coerce}){ defined($tc) @@ -506,8 +511,7 @@ sub _process_options{ } -package - Mouse::Meta::TypeConstraint; +package Mouse::Meta::TypeConstraint; sub name { $_[0]->{name} } sub parent { $_[0]->{parent} } @@ -569,8 +573,7 @@ sub compile_type_constraint{ return; } -package - Mouse::Object; +package Mouse::Object; sub BUILDARGS {