X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FClass.pm;h=90331ad542dbc5b71577f61be56701c67582b2ca;hb=6d46df7af00723bd7a0972abf5e5d62481ff6435;hp=642f7389319b89d691880cc51b125d2b02cb2db1;hpb=6c169c5063b77a791818f5db2c1da3bd9b47d3f9;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Class.pm b/lib/Mouse/Meta/Class.pm index 642f738..90331ad 100644 --- a/lib/Mouse/Meta/Class.pm +++ b/lib/Mouse/Meta/Class.pm @@ -1,4 +1,3 @@ -#!/usr/bin/env perl package Mouse::Meta::Class; use strict; use warnings; @@ -64,6 +63,7 @@ sub add_method { my $pkg = $self->name; no strict 'refs'; + $self->{'methods'}->{$name}++; # Moose stores meta object here. *{ $pkg . '::' . $name } = $code; } @@ -74,10 +74,11 @@ sub get_method_list { no strict 'refs'; # Get all the CODE symbol table entries - my @functions = grep !/^meta$/, - grep { /\A[^\W\d]\w*\z/o } + my @functions = + grep !/^(?:has|with|around|before|after|blessed|extends|confess)$/, grep { defined &{"${name}::$_"} } keys %{"${name}::"}; + push @functions, keys %{$self->{'methods'}->{$name}}; wantarray ? @functions : \@functions; } @@ -143,15 +144,17 @@ sub clone_instance { sub make_immutable { my $self = shift; + my %args = @_; my $name = $self->name; $self->{is_immutable}++; - no strict 'refs'; - *{"$name\::new"} = Mouse::Meta::Method::Constructor->generate_constructor_method_inline( $self ); - *{"$name\::DESTROY"} = Mouse::Meta::Method::Destructor->generate_destructor_method_inline( $self ); -} -sub make_mutable { - Carp::croak "Mouse::Meta::Class->make_mutable does not supported by Mouse"; + $self->add_method('new' => Mouse::Meta::Method::Constructor->generate_constructor_method_inline( $self )); + if ($args{inline_destructor}) { + $self->add_method('DESTROY' => Mouse::Meta::Method::Destructor->generate_destructor_method_inline( $self )); + } } + +sub make_mutable { confess "Mouse does not currently support 'make_mutable'" } + sub is_immutable { $_[0]->{is_immutable} } sub attribute_metaclass { "Mouse::Meta::Class" } @@ -193,11 +196,14 @@ sub roles { $_[0]->{roles} } sub does_role { my ($self, $role_name) = @_; + (defined $role_name) || confess "You must supply a role name to look for"; + for my $role (@{ $self->{roles} }) { return 1 if $role->name eq $role_name; } + return 0; } @@ -212,14 +218,14 @@ sub create { (ref $options{superclasses} eq 'ARRAY') || confess "You must pass an ARRAY ref of superclasses" if exists $options{superclasses}; - + (ref $options{attributes} eq 'ARRAY') || confess "You must pass an ARRAY ref of attributes" - if exists $options{attributes}; - + if exists $options{attributes}; + (ref $options{methods} eq 'HASH') || confess "You must pass a HASH ref of methods" - if exists $options{methods}; + if exists $options{methods}; do { # XXX should I implement Mouse::Meta::Module?