X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FModule.pm;h=7d2a1e9fbf1bab1223da156c4902807065a7f747;hp=b9281a8a2e39910d332cfda88bedbbc334b477e5;hb=637d4f17e6965551c032a3115dcbbb4d8e01fbf5;hpb=542f20adaffff1539921032f24c8c1893080fc8c diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index b9281a8..7d2a1e9 100755 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -1,12 +1,12 @@ package Mouse::Meta::Module; -use Mouse::Util qw/:meta get_code_package get_code_ref load_class not_supported/; # enables strict and warnings +use Mouse::Util qw/:meta get_code_package get_code_ref not_supported/; # enables strict and warnings use Carp (); use Scalar::Util (); my %METAS; -if(Mouse::Util::_MOUSE_XS){ +if(Mouse::Util::MOUSE_XS){ # register meta storage for performance Mouse::Util::__register_metaclass_storage(\%METAS, 0); @@ -16,6 +16,7 @@ if(Mouse::Util::_MOUSE_XS){ sub _metaclass_cache { # DEPRECATED my($class, $name) = @_; + Carp::cluck('_metaclass_cache() has been deprecated. Use Mouse::Util::get_metaclass_by_name() instead'); return $METAS{$name}; } @@ -32,6 +33,8 @@ sub initialize { sub reinitialize { my($class, $package_name, @args) = @_; + $package_name = $package_name->name if ref $package_name; + ($package_name && !ref($package_name)) || $class->throw_error("You must pass a package name and it cannot be blessed"); @@ -76,7 +79,7 @@ sub namespace; # add_attribute is an abstract method sub get_attribute_map { # DEPRECATED - Carp::cluck('get_attribute_map() has been deprecated'); + Carp::cluck('get_attribute_map() has been deprecated. Use get_attribute_list() and get_attribute() instead'); return $_[0]->{attributes}; } @@ -86,7 +89,6 @@ sub remove_attribute { delete $_[0]->{attributes}->{$_[1]} } sub get_attribute_list{ keys %{$_[0]->{attributes}} } - # XXX: for backward compatibility my %foreign = map{ $_ => undef } qw( Mouse Mouse::Role Mouse::Util Mouse::Util::TypeConstraints @@ -128,10 +130,7 @@ sub get_method{ my($self, $method_name) = @_; if(my $code = $self->get_method_body($method_name)){ - my $method_metaclass = $self->method_metaclass; - load_class($method_metaclass); - - return $method_metaclass->wrap( + return Mouse::Util::load_class($self->method_metaclass)->wrap( body => $code, name => $method_name, package => $self->name, @@ -148,6 +147,37 @@ sub get_method_list { return grep { $self->has_method($_) } keys %{ $self->namespace }; } +sub _collect_methods { # Mouse specific + my($meta, @args) = @_; + + my @methods; + foreach my $arg(@args){ + if(my $type = ref $arg){ + if($type eq 'Regexp'){ + push @methods, grep { $_ =~ $arg } $meta->get_all_method_names; + } + elsif($type eq 'ARRAY'){ + push @methods, @{$arg}; + } + else{ + my $subname = ( caller(1) )[3]; + $meta->throw_error( + sprintf( + 'Methods passed to %s must be provided as a list, ArrayRef or regular expression, not %s', + $subname, + $type, + ) + ); + } + } + else{ + push @methods, $arg; + } + } + return @methods; +} + + { my $ANON_SERIAL = 0; @@ -262,6 +292,8 @@ sub get_method_list { sub DESTROY{ my($self) = @_; + return if $Mouse::Util::in_global_destruction; + my $serial_id = $self->{anon_serial_id}; return if !$serial_id; @@ -299,7 +331,6 @@ sub throw_error{ } 1; - __END__ =head1 NAME @@ -308,7 +339,7 @@ Mouse::Meta::Module - The base class for Mouse::Meta::Class and Mouse::Meta::Rol =head1 VERSION -This document describes Mouse version 0.40_06 +This document describes Mouse version 0.50_03 =head1 SEE ALSO