X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FModule.pm;h=9fefa10379bfc59f493d3af0815d8456baec31b5;hb=78dc5ed14c0d04c8b73dc8ec701704d72b68e32c;hp=25831a99a4ca294a2c285a5531e91eab86b6e105;hpb=e75f21db61e436b0a3646c6edba9a3d1aae7d696;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index 25831a9..9fefa10 100755 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -10,9 +10,7 @@ use Mouse::Util qw/:meta get_code_package not_supported load_class/; my %METAS; -# because Mouse doesn't introspect existing classes, we're forced to -# only pay attention to other Mouse classes -sub _metaclass_cache { +sub _metaclass_cache { # DEPRECATED my($class, $name) = @_; return $METAS{$name}; } @@ -63,7 +61,7 @@ sub name { $_[0]->{package} } # add_attribute is an abstract method -sub get_attribute_map { +sub get_attribute_map { # DEPRECATED Carp::cluck('get_attribute_map() has been deprecated'); return $_[0]->{attributes}; } @@ -90,7 +88,7 @@ sub add_method { } if(ref($code) ne 'CODE'){ - not_supported 'add_method for a method object'; + $code = \&{$code}; # coerce } $self->{methods}->{$name}++; # Moose stores meta object here. @@ -117,6 +115,9 @@ sub _code_is_mine{ sub has_method { my($self, $method_name) = @_; + defined($method_name) + or $self->throw_error('You must define a method name'); + return 1 if $self->{methods}->{$method_name}; my $code = do{ no strict 'refs'; *{$self->{package} . '::' . $method_name}{CODE} }; @@ -154,36 +155,37 @@ sub get_method_list { my %IMMORTALS; sub create { - my($class, $package_name, %options) = @_; + my($self, $package_name, %options) = @_; - $class->throw_error('You must pass a package name') if @_ < 2; + my $class = ref($self) || $self; + $self->throw_error('You must pass a package name') if @_ < 2; my $superclasses; if(exists $options{superclasses}){ - if($class->isa('Mouse::Meta::Role')){ + if($self->isa('Mouse::Meta::Role')){ delete $options{superclasses}; } else{ $superclasses = delete $options{superclasses}; (ref $superclasses eq 'ARRAY') - || $class->throw_error("You must pass an ARRAY ref of superclasses"); + || $self->throw_error("You must pass an ARRAY ref of superclasses"); } } my $attributes = delete $options{attributes}; if(defined $attributes){ (ref $attributes eq 'ARRAY' || ref $attributes eq 'HASH') - || $class->throw_error("You must pass an ARRAY ref of attributes"); + || $self->throw_error("You must pass an ARRAY ref of attributes"); } my $methods = delete $options{methods}; if(defined $methods){ (ref $methods eq 'HASH') - || $class->throw_error("You must pass a HASH ref of methods"); + || $self->throw_error("You must pass a HASH ref of methods"); } my $roles = delete $options{roles}; if(defined $roles){ (ref $roles eq 'ARRAY') - || $class->throw_error("You must pass an ARRAY ref of roles"); + || $self->throw_error("You must pass an ARRAY ref of roles"); } my $mortal; my $cache_key; @@ -211,14 +213,13 @@ sub get_method_list { ${ $package_name . '::AUTHORITY' } = delete $options{authority} if exists $options{authority}; } - my $meta = $class->initialize( $package_name, %options); + my $meta = $self->initialize( $package_name, %options); weaken $METAS{$package_name} if $mortal; - # FIXME totally lame - $meta->add_method('meta' => sub { - $class->initialize(ref($_[0]) || $_[0]); + $meta->add_method(meta => sub{ + $self->initialize(ref($_[0]) || $_[0]); }); $meta->superclasses(@{$superclasses})