X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FPurePerl.pm;h=73374b4cd1dea0dd4e31bc598c15875df0e22f74;hb=b4dc931582100f9ec9ec48e0ac1be81cc8e66c84;hp=ac9494751bc9488dd87a9c4ce45efb951d420fee;hpb=4bef84ef7f1835abdcab5c23f9a74446349749d8;p=gitmo%2FMouse.git diff --git a/lib/Mouse/PurePerl.pm b/lib/Mouse/PurePerl.pm index ac94947..73374b4 100644 --- a/lib/Mouse/PurePerl.pm +++ b/lib/Mouse/PurePerl.pm @@ -242,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; @@ -363,23 +384,9 @@ 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 -} +Mouse::Util::install_subroutines(__PACKAGE__, + strict_constructor => $generate_class_accessor->('strict_constructor'), +); sub _report_unknown_args { my($metaclass, $attrs, $args) = @_; @@ -447,6 +454,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; @@ -628,6 +641,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} } @@ -777,7 +797,7 @@ Mouse::PurePerl - A Mouse guts in pure Perl =head1 VERSION -This document describes Mouse version 0.68 +This document describes Mouse version 0.70 =head1 SEE ALSO