use strict;
use warnings;
-use Test::More tests => 67;
+use Test::More tests => 65;
use Test::Exception;
use Scalar::Util qw/reftype/;
}
}
-{
- package Foo::Aliasing;
- use metaclass;
- sub alias_me { '...' }
-}
-
-$Foo->alias_method('alias_me' => Foo::Aliasing->meta->get_method('alias_me'));
-
-ok($Foo->has_method('alias_me'), '... Foo->has_method(alias_me) (aliased from Foo::Aliasing)');
-ok(defined &Foo::alias_me, '... Foo does have a symbol table slow for alias_me though');
-
ok(!$Foo->has_method('blessed'), '... !Foo->has_method(blessed) (imported into Foo)');
ok(!$Foo->has_method('boom'), '... !Foo->has_method(boom) (defined in main:: using symbol tables and Sub::Name w/out package name)');
is_deeply(
[ sort $Foo->get_method_list ],
- [ qw(FOO_CONSTANT alias_me baaz bang bar baz blah cake evaled_foo floob foo pie) ],
+ [ qw(FOO_CONSTANT baaz bang bar baz blah cake evaled_foo floob foo pie) ],
'... got the right method list for Foo');
is_deeply(
[
map { $Foo->get_method($_) } qw(
FOO_CONSTANT
- alias_me
baaz
bang
bar
is_deeply(
[ sort $Foo->get_method_list ],
- [ qw(FOO_CONSTANT alias_me baaz bang bar baz blah cake evaled_foo floob pie) ],
+ [ qw(FOO_CONSTANT baaz bang bar baz blah cake evaled_foo floob pie) ],
'... got the right method list for Foo');
[ sort { $a->name cmp $b->name } $Bar->get_all_methods() ],
[
$Foo->get_method('FOO_CONSTANT'),
- $Foo->get_method('alias_me'),
$Foo->get_method('baaz'),
$Foo->get_method('bang'),
$Bar->get_method('bar'),
use strict;
use warnings;
-use Test::More tests => 12;
+use Test::More tests => 11;
use Test::Exception;
use Class::MOP;
],
'... got the right list of applicable methods for Foo::Bar');
-# test compute_all_applicable_methods once for compat
-is_deeply(
- [ sort { $a->{name} cmp $b->{name} } Class::MOP::Class->initialize('Foo::Bar::Baz')->compute_all_applicable_methods() ],
- [
- {
- name => 'BUILD',
- class => 'Foo::Bar::Baz',
- code => Class::MOP::Class->initialize('Foo::Bar::Baz')->get_method('BUILD')
- },
- {
- name => 'bar',
- class => 'Foo::Bar::Baz',
- code => Class::MOP::Class->initialize('Foo::Bar::Baz')->get_method('bar')
- },
- {
- name => 'baz',
- class => 'Baz',
- code => Class::MOP::Class->initialize('Baz')->get_method('baz')
- },
- {
- name => 'foo',
- class => 'Foo',
- code => Class::MOP::Class->initialize('Foo')->get_method('foo')
- },
- {
- name => 'foobarbaz',
- class => 'Foo::Bar::Baz',
- code => Class::MOP::Class->initialize('Foo::Bar::Baz')->get_method('foobarbaz')
- },
- ],
- '... got the right list of applicable methods for Foo::Bar::Baz');
-
## find_all_methods_by_name
is_deeply(
use strict;
use warnings;
-use Test::More tests => 114;
+use Test::More tests => 101;
use Test::Exception;
use Scalar::Util;
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 register');
- is( Baz->zxy, 'xxx', '... method zxy works');
- ok( $meta->remove_method('xyz'), '... removed method');
- ok( $meta->remove_method('zxy'), '... removed aliased method');
-
ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute');
ok(Baz->can('fickle'), '... Baz can fickle');
ok($meta->remove_attribute('fickle'), '... removed attribute');
lives_ok { $meta->make_immutable() } '... changed Baz to be immutable';
dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected';
- dies_ok{ $meta->alias_method('zxy',sub{'xxx'}) } '... exception thrown as expected';
- dies_ok{ $meta->remove_method('zxy') } '... exception thrown as expected';
dies_ok {
$meta->add_attribute('fickle', accessor => 'fickle')
ok(Baz->meta->is_immutable, 'Superclass is immutable');
my $meta = Baz->meta->create_anon_class(superclasses => ['Baz']);
my @orig_keys = sort grep { !/^_/ } keys %$meta;
- my @orig_meths = sort { $a->{name} cmp $b->{name} }
- $meta->compute_all_applicable_methods;
+ my @orig_meths = sort { $a->name cmp $b->name }
+ $meta->get_all_methods;
ok($meta->is_anon_class, 'We have an anon metaclass');
ok($meta->is_mutable, '... our anon class is mutable');
ok(!$meta->is_immutable, '... our anon class is not immutable');
my $instance = $meta->new_object;
my @new_keys = sort grep { !/^_/ } keys %$meta;
- my @new_meths = sort { $a->{name} cmp $b->{name} }
- $meta->compute_all_applicable_methods;
+ my @new_meths = sort { $a->name cmp $b->name }
+ $meta->get_all_methods;
is_deeply(\@orig_keys, \@new_keys, '... no straneous hashkeys');
is_deeply(\@orig_meths, \@new_meths, '... no straneous methods');
ok( $meta->add_method('xyz', sub{'xxx'}), '... added method');
is( $instance->xyz , 'xxx', '... method xyz works');
- ok( $meta->alias_method('zxy',sub{'xxx'}),'... aliased method');
- is( $instance->zxy, 'xxx', '... method zxy works');
ok( $meta->remove_method('xyz'), '... removed method');
- ok( $meta->remove_method('zxy'), '... removed aliased method');
ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute');
ok($instance->can('fickle'), '... instance can fickle');
lives_ok {$meta->make_immutable } '... changed class to be immutable';
dies_ok{ $meta->add_method('xyz', sub{'xxx'}) } '... exception thrown as expected';
- dies_ok{ $meta->alias_method('zxy',sub{'xxx'}) } '... exception thrown as expected';
- dies_ok{ $meta->remove_method('zxy') } '... exception thrown as expected';
dies_ok {
$meta->add_attribute('fickle', accessor => 'fickle')