X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FClass.pm;h=f4a94e42c5adc787cf7cf09826bf40d0051e6693;hb=e0b163e1eae55efa02feae5a207b68b00734c124;hp=8e89567673f0389743dbd1164f7b65cfe8bc3f9a;hpb=60f6eba91f12d48fa30a8e16abe2db8c95b4d878;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 8e89567..f4a94e4 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -5,7 +5,7 @@ use warnings; use Mouse::Meta::Method::Constructor; use Mouse::Meta::Method::Destructor; use Scalar::Util qw/blessed/; -use Mouse::Util qw/get_linear_isa/; +use Mouse::Util qw/get_linear_isa version authority identifier/; use Carp 'confess'; do { @@ -20,8 +20,9 @@ do { } sub initialize { - my $class = shift; - my $name = shift; + my $class = blessed($_[0]) || $_[0]; + my $name = $_[1]; + $METACLASS_CACHE{$name} = $class->new(name => $name) if !exists($METACLASS_CACHE{$name}); return $METACLASS_CACHE{$name}; @@ -68,6 +69,12 @@ sub add_method { *{ $pkg . '::' . $name } = $code; } +sub has_method { + my $self = shift; + my $name = shift; + $self->name->can($name); +} + # copied from Class::Inspector my $get_methods_for_class = sub { my $self = shift; @@ -76,7 +83,7 @@ my $get_methods_for_class = sub { no strict 'refs'; # Get all the CODE symbol table entries my @functions = - grep !/^(?:has|with|around|before|after|blessed|extends|confess|override|super)$/, + grep !/^(?:has|with|around|before|after|augment|inner|blessed|extends|confess|override|super)$/, grep { defined &{"${name}::$_"} } keys %{"${name}::"}; push @functions, keys %{$self->{'methods'}->{$name}} if $self; @@ -260,6 +267,22 @@ sub add_after_method_modifier { $self->_install_modifier( $self->name, 'after', $name, $code ); } +sub add_override_method_modifier { + my ($self, $name, $code) = @_; + + my $pkg = $self->name; + my $method = "${pkg}::${name}"; + + # Class::Method::Modifiers won't do this for us, so do it ourselves + + my $body = $pkg->can($name) + or confess "You cannot override '$method' because it has no super method"; + + no strict 'refs'; + *$method = sub { $code->($pkg, $body, @_) }; +} + + sub roles { $_[0]->{roles} } sub does_role {