# define a sub in package
sub bar { 'Foo::bar' }
*baz = \&bar;
+
+ # create something with the typeglob inside the package
+ *baaz = sub { 'Foo::baaz' };
{ # method named with Sub::Name inside the package scope
no strict 'refs';
}
# We hateses the "used only once" warnings
- { my $temp = \&Foo::baz }
+ {
+ my $temp1 = \&Foo::baz;
+ my $temp2 = \&Foo::baaz;
+ }
package OinkyBoinky;
our @ISA = "Foo";
# now check all our other items ...
-ok($Foo->has_method('FOO_CONSTANT'), '... Foo->has_method(FOO_CONSTANT) (defined w/ use constant)');
+ok(!$Foo->has_method('FOO_CONSTANT'), '... Foo->has_method(FOO_CONSTANT) (defined w/ use constant)');
+ok(!$Foo->has_method('bling'), '... Foo->has_method(bling) (defined in main:: using symbol tables (no Sub::Name))');
+
ok($Foo->has_method('bar'), '... Foo->has_method(bar) (defined in Foo)');
ok($Foo->has_method('baz'), '... Foo->has_method(baz) (typeglob aliased within Foo)');
+ok($Foo->has_method('baaz'), '... Foo->has_method(baaz) (typeglob aliased within Foo)');
ok($Foo->has_method('floob'), '... Foo->has_method(floob) (defined in Foo:: using symbol tables and Sub::Name w/out package name)');
ok($Foo->has_method('blah'), '... Foo->has_method(blah) (defined in main:: using fully qualified package name)');
-ok($Foo->has_method('bling'), '... Foo->has_method(bling) (defined in main:: using symbol tables (no Sub::Name))');
ok($Foo->has_method('bang'), '... Foo->has_method(bang) (defined in main:: using symbol tables and Sub::Name)');
ok($Foo->has_method('evaled_foo'), '... Foo->has_method(evaled_foo) (evaled in main::)');
# calling get_method blessed them all
-for my $method_name (qw/FOO_CONSTANT
- bar
+for my $method_name (qw/baaz
+ bar
baz
floob
- blah
- bling
- bang
+ blah
+ bang
evaled_foo/) {
isa_ok($Foo->get_method($method_name), 'Class::MOP::Method');
{
}
}
+for my $method_name (qw/
+ FOO_CONSTANT
+ bling
+ /) {
+ is(ref($Foo->get_package_symbol('&' . $method_name)), 'CODE', '... got the __ANON__ methods');
+ {
+ no strict 'refs';
+ is($Foo->get_package_symbol('&' . $method_name), \&{'Foo::' . $method_name}, '... symbol matches CODE ref in package for ' . $method_name);
+ }
+}
+
{
package Foo::Aliasing;
use metaclass;
is_deeply(
[ sort $Foo->get_method_list ],
- [ qw(FOO_CONSTANT bang bar baz blah bling evaled_foo floob foo) ],
+ [ qw(baaz bang bar baz blah evaled_foo floob foo) ],
'... got the right method list for Foo');
is_deeply(
code => $Foo->get_method($_)
}
} qw(
- FOO_CONSTANT
+ baaz
bang
bar
baz
blah
- bling
evaled_foo
floob
foo
is_deeply(
[ sort $Foo->get_method_list ],
- [ qw(FOO_CONSTANT bang bar baz blah bling evaled_foo floob) ],
+ [ qw(baaz bang bar baz blah evaled_foo floob) ],
'... got the right method list for Foo');
-ok($Foo->remove_method('FOO_CONSTANT'), '... removed the FOO_CONSTANT method');
-ok(!$Foo->has_method('FOO_CONSTANT'), '... !Foo->has_method(FOO_CONSTANT) we just removed it');
-dies_ok { Foo->FOO_CONSTANT } '... cannot call Foo->FOO_CONSTANT because it is not there';
-
is_deeply(
[ sort $Foo->get_method_list ],
- [ qw(bang bar baz blah bling evaled_foo floob) ],
+ [ qw(baaz bang bar baz blah evaled_foo floob) ],
'... got the right method list for Foo');
# ... test our class creator
[ sort { $a->{name} cmp $b->{name} } $Bar->compute_all_applicable_methods() ],
[
{
+ name => 'baaz',
+ class => 'Foo',
+ code => $Foo->get_method('baaz')
+ },
+ {
name => 'bang',
class => 'Foo',
code => $Foo->get_method('bang')
} qw(
baz
blah
- bling
evaled_foo
floob
)),
use strict;
use warnings;
-use Test::More tests => 108;
+use Test::More tests => 112;
use Test::Exception;
use Scalar::Util;
ok($meta->is_immutable, '... our class is now immutable');
ok(!$meta->make_immutable, '... make immutable now returns nothing');
ok($meta->get_method_map->{new}, '... inlined constructor created');
+ ok($meta->has_method('new'), '... inlined constructor created for sure');
lives_ok { $meta->make_mutable; } '... changed Baz to be mutable';
ok($meta->is_mutable, '... our class is mutable');
ok(!$meta->is_immutable, '... our class is not immutable');
ok(!$meta->make_mutable, '... make mutable now returns nothing');
ok(!$meta->get_method_map->{new}, '... inlined constructor removed');
+ ok(!$meta->has_method('new'), '... inlined constructor removed for sure');
my @new_keys = sort keys %$meta;
is_deeply(\@orig_keys, \@new_keys, '... no straneous hashkeys');
ok( $meta->add_method('xyz', sub{'xxx'}), '... added method');
is( Baz->xyz, 'xxx', '... method xyz works');
+
+ ok(! $meta->has_method('zxy') ,'... we dont have the aliased method yet');
ok( $meta->alias_method('zxy',sub{'xxx'}),'... aliased method');
+ ok(! $meta->has_method('zxy') ,'... the aliased method does not register (correctly)');
is( Baz->zxy, 'xxx', '... method zxy works');
ok( $meta->remove_method('xyz'), '... removed method');
ok(! $meta->remove_method('zxy'), '... removed aliased method');