my $pkg = $self->name;
no strict 'refs';
+ $self->{'methods'}->{$name}++; # Moose stores meta object here.
*{ $pkg . '::' . $name } = $code;
}
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;
}
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 );
+ $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 {
Carp::croak "Mouse::Meta::Class->make_mutable does not supported by Mouse";
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|excludes|meta|requires)/,
grep { defined &{"${name}::$_"} }
keys %{"${name}::"};
wantarray ? @functions : \@functions;
{
no strict 'refs';
for my $name ($self->get_method_list) {
- next if $name eq 'has' || $name eq 'requires' || $name eq 'meta' || $name eq 'with' || $name eq 'around' || $name eq 'before' || $name eq 'after' || $name eq 'blessed' || $name eq 'extends' || $name eq 'confess' || $name eq 'excludes';
+ next if $name eq 'meta';
if ($classname->can($name)) {
# XXX what's Moose's behavior?
my $selfname = $self->name;
my %args = %{ $role_spec->[1] };
for my $name ($self->get_method_list) {
- next if $name eq 'has' || $name eq 'requires' || $name eq 'meta' || $name eq 'with' || $name eq 'around' || $name eq 'before' || $name eq 'after' || $name eq 'blessed' || $name eq 'extends' || $name eq 'confess' || $name eq 'excludes';
+ next if $name eq 'meta';
if ($classname->can($name)) {
# XXX what's Moose's behavior?
$self->y(0);
}
+ __PACKAGE__->meta->make_immutable();
}{
package Point3D;
use Mouse;
$self->{z} = 0;
};
+ __PACKAGE__->meta->make_immutable();
}
my $point = Point->new(x => 1, y => 2);
my @Point_methods = qw(meta new x y clear);
my @Point_attrs = ('x', 'y');
-SKIP: {
- skip "Mouse has no method introspection", 2 + @Point_methods;
+is_deeply(
+ [ sort @Point_methods ],
+ [ sort Point->meta->get_method_list() ],
+ '... we match the method list for Point');
- is_deeply(
- [ sort @Point_methods ],
- [ sort Point->meta->get_method_list() ],
- '... we match the method list for Point');
+SKIP: {
+ skip "Mouse has no method introspection", 1 + @Point_methods;
is_deeply(
[ sort @Point_attrs ],
my $baz = Baz->new;
is $baz->foo, 'ok1';
is $baz->bar, 'ok2';
-is join(",", sort $baz->meta->get_method_list), 'bar,foo';
+is join(",", sort $baz->meta->get_method_list), 'bar,foo,meta';
--- /dev/null
+use strict;
+use warnings;
+use Test::More;
+plan skip_all => "This test requires Moose" unless eval "require Moose; 1;";
+plan tests => 6;
+
+test($_) for qw/Moose Mouse/;
+exit;
+
+sub test {
+ my $class = shift;
+ eval <<"...";
+{
+ package ${class}Class;
+ use ${class};
+ sub foo { }
+ no ${class};
+}
+{
+ package ${class}ClassImm;
+ use ${class};
+ sub foo { }
+ no ${class};
+ __PACKAGE__->meta->make_immutable();
+}
+{
+ package ${class}Role;
+ use ${class}::Role;
+ sub bar { }
+}
+...
+ die $@ if $@;
+ is join(',', sort "${class}Class"->meta->get_method_list()), 'foo,meta';
+ is join(',', sort "${class}ClassImm"->meta->get_method_list()), 'foo,meta,new';
+ is join(',', sort "${class}Role"->meta->get_method_list()), 'bar';
+}
+