X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FPurePerl.pm;h=36ef0cef0250beb2b234195b7a44dbe7e5023666;hb=823419c540f9e77090f31f11e04b14477c0372c4;hp=db2bf6239d2be7f122983fc87ae37449d3084a15;hpb=1038bfa9e8a49b9c9f9ce872c46800f9590da8ed;p=gitmo%2FMouse.git diff --git a/lib/Mouse/PurePerl.pm b/lib/Mouse/PurePerl.pm index db2bf62..36ef0ce 100644 --- a/lib/Mouse/PurePerl.pm +++ b/lib/Mouse/PurePerl.pm @@ -1,16 +1,14 @@ package Mouse::PurePerl; - -require Mouse::Util; - +# The pure Perl backend for Mouse package Mouse::Util; - use strict; use warnings; - -use warnings FATAL => 'redefine'; # to avoid to load Mouse::PurePerl +use warnings FATAL => 'redefine'; # to avoid to load Mouse::PurePerl twice use B (); +require Mouse::Util; + # taken from Class/MOP.pm sub is_valid_class_name { @@ -244,6 +242,27 @@ sub add_method { return; } +my $generate_class_accessor = sub { + my($name) = @_; + return sub { + my $self = shift; + if(@_) { + return $self->{$name} = shift; + } + + foreach my $class($self->linearized_isa) { + my $meta = Mouse::Util::get_metaclass_by_name($class) + or next; + + if(exists $meta->{$name}) { + return $meta->{$name}; + } + } + return undef; + }; +}; + + package Mouse::Meta::Class; use Mouse::Meta::Method::Constructor; @@ -365,23 +384,8 @@ sub _initialize_object{ sub is_immutable { $_[0]->{is_immutable} } -sub strict_constructor{ - my $self = shift; - if(@_) { - $self->{strict_constructor} = shift; - } - - foreach my $class($self->linearized_isa) { - my $meta = Mouse::Util::get_metaclass_by_name($class) - or next; - - if(exists $meta->{strict_constructor}) { - return $meta->{strict_constructor}; - } - } - - return 0; # false -} +sub strict_constructor; +*strict_constructor = $generate_class_accessor->('strict_constructor'); sub _report_unknown_args { my($metaclass, $attrs, $args) = @_; @@ -449,6 +453,12 @@ sub get_after_method_modifiers { return @{ $self->{after_method_modifiers}{$method_name} ||= [] } } +sub add_metaclass_accessor { # for meta roles (a.k.a. traits) + my($meta, $name) = @_; + $meta->add_method($name => $generate_class_accessor->($name)); + return; +} + package Mouse::Meta::Attribute; require Mouse::Meta::Method::Accessor; @@ -630,6 +640,13 @@ sub _process_options{ package Mouse::Meta::TypeConstraint; +use overload + '""' => '_as_string', + '0+' => '_identity', + '|' => '_unite', + + fallback => 1; + sub name { $_[0]->{name} } sub parent { $_[0]->{parent} } sub message { $_[0]->{message} } @@ -779,7 +796,7 @@ Mouse::PurePerl - A Mouse guts in pure Perl =head1 VERSION -This document describes Mouse version 0.65 +This document describes Mouse version 0.70 =head1 SEE ALSO