use strict;
use warnings;
-use Test::More tests => 67;
+use Test::More;
use Test::Exception;
use Scalar::Util qw/reftype/;
my $Foo = Class::MOP::Class->initialize('Foo');
+is join(' ', sort $Foo->get_method_list),
+ 'FOO_CONSTANT baaz bang bar baz blah cake evaled_foo floob pie';
+
ok( $Foo->has_method('pie'), '... got the method stub pie' );
ok( $Foo->has_method('cake'), '... got the constant method stub cake' );
is( $Foo->remove_method('foo')->body, $foo, '... removed the foo method' );
ok( !$Foo->has_method('foo'),
'... !Foo->has_method(foo) we just removed it' );
-ok( !$Foo->get_method_map->{foo}, 'foo is not in the method map' );
dies_ok { Foo->foo } '... cannot call Foo->foo because it is not there';
is_deeply(
}
);
- $meta->add_method( 'new', sub { return bless {}, shift } );
+ sub new {
+ return bless {}, shift;
+ }
}
{
is(
$o->{custom_store}, $str,
- 'Custom glob-assignment-created accessor is still method modifier is added'
+ 'Custom glob-assignment-created accessor still has method modifier'
);
}
+
+{
+ # Since the sub reference below is not a closure, Perl caches it and uses
+ # the same reference each time through the loop. See RT #48985 for the
+ # bug.
+ foreach my $ns ( qw( Foo2 Bar2 Baz2 ) ) {
+ my $meta = Class::MOP::Class->create($ns);
+
+ my $sub = sub { };
+
+ $meta->add_method( 'foo', $sub );
+
+ my $method = $meta->get_method('foo');
+ ok( $method, 'Got the foo method back' );
+ }
+}
+
+{
+ package HasConstants;
+
+ use constant FOO => 1;
+ use constant BAR => [];
+ use constant BAZ => {};
+ use constant UNDEF => undef;
+
+ sub quux {1}
+ sub thing {1}
+}
+
+my $HC = Class::MOP::Class->initialize('HasConstants');
+
+is_deeply(
+ [ sort $HC->get_method_list ],
+ [qw( BAR BAZ FOO UNDEF quux thing )],
+ 'get_method_list handles constants properly'
+);
+
+is_deeply(
+ [ sort map { $_->name } $HC->_get_local_methods ],
+ [qw( BAR BAZ FOO UNDEF quux thing )],
+ '_get_local_methods handles constants properly'
+);
+
+
+done_testing;