X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F073_make_mutable.t;h=d15626ee5a9363a9fc7132fe84db58458b4baea1;hb=0156915cde1934bb6fd67d3a2c9930de45a86c05;hp=1c2998182da036a3ac68b3af7308b305f16c9b7e;hpb=46b23b447c9ab2e7681b7377d505f2ad6fbc39b3;p=gitmo%2FClass-MOP.git diff --git a/t/073_make_mutable.t b/t/073_make_mutable.t index 1c29981..d15626e 100644 --- a/t/073_make_mutable.t +++ b/t/073_make_mutable.t @@ -1,16 +1,12 @@ -#!/usr/bin/perl - use strict; use warnings; -use Test::More tests => 112; +use Test::More tests => 99; use Test::Exception; use Scalar::Util; -BEGIN { - use_ok('Class::MOP'); -} +use Class::MOP; { package Foo; @@ -45,7 +41,9 @@ BEGIN { { my $meta = Baz->meta; is($meta->name, 'Baz', '... checking the Baz metaclass'); - my @orig_keys = sort keys %$meta; + my %orig_keys = map { $_ => 1 } grep { !/^_/ } keys %$meta; + # Since this has no default it won't be present yet, but it will + # be after the class is made immutable. lives_ok {$meta->make_immutable; } '... changed Baz to be immutable'; ok(!$meta->is_mutable, '... our class is no longer mutable'); @@ -53,6 +51,7 @@ BEGIN { 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'); + is_deeply([ map { $_->name } $meta->_inlined_methods ], [ 'new' ], '... really, i mean it'); lives_ok { $meta->make_mutable; } '... changed Baz to be mutable'; ok($meta->is_mutable, '... our class is mutable'); @@ -61,21 +60,14 @@ BEGIN { 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'); + my %new_keys = map { $_ => 1 } grep { !/^_/ } keys %$meta; + is_deeply(\%orig_keys, \%new_keys, '... no extraneous hashkeys'); isa_ok($meta, 'Class::MOP::Class', '... Baz->meta isa Class::MOP::Class'); 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'); - ok($meta->add_attribute('fickle', accessor => 'fickle'), '... added attribute'); ok(Baz->can('fickle'), '... Baz can fickle'); ok($meta->remove_attribute('fickle'), '... removed attribute'); @@ -93,7 +85,7 @@ BEGIN { is_deeply([@supers], [$meta->superclasses], '... reset the superclasses okay'); ok( $meta->$_ , "... ${_} works") - for qw(get_meta_instance compute_all_applicable_attributes + for qw(get_meta_instance get_all_attributes class_precedence_list get_method_map ); lives_ok {$meta->make_immutable; } '... changed Baz to be immutable again'; @@ -108,8 +100,6 @@ BEGIN { 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') @@ -124,7 +114,7 @@ BEGIN { dies_ok { $meta->superclasses('Foo') } '... set the superclasses'; ok( $meta->$_ , "... ${_} works") - for qw(get_meta_instance compute_all_applicable_attributes + for qw(get_meta_instance get_all_attributes class_precedence_list get_method_map ); } @@ -132,9 +122,8 @@ BEGIN { ok(Baz->meta->is_immutable, 'Superclass is immutable'); my $meta = Baz->meta->create_anon_class(superclasses => ['Baz']); - my @orig_keys = sort keys %$meta; - my @orig_meths = sort { $a->{name} cmp $b->{name} } - $meta->compute_all_applicable_methods; + my %orig_keys = map { $_ => 1 } grep { !/^_/ } keys %$meta; + 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'); @@ -156,20 +145,17 @@ BEGIN { ok($meta->is_anon_class, '... still marked as an anon class'); my $instance = $meta->new_object; - my @new_keys = sort keys %$meta; - my @new_meths = sort { $a->{name} cmp $b->{name} } - $meta->compute_all_applicable_methods; - is_deeply(\@orig_keys, \@new_keys, '... no straneous hashkeys'); + my %new_keys = map { $_ => 1 } grep { !/^_/ } keys %$meta; + my @new_meths = sort { $a->name cmp $b->name } + $meta->get_all_methods; + is_deeply(\%orig_keys, \%new_keys, '... no extraneous hashkeys'); is_deeply(\@orig_meths, \@new_meths, '... no straneous methods'); isa_ok($meta, 'Class::MOP::Class', '... Anon class isa Class::MOP::Class'); 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'); @@ -188,7 +174,7 @@ BEGIN { is_deeply([@supers], [$meta->superclasses], '... reset the superclasses okay'); ok( $meta->$_ , "... ${_} works") - for qw(get_meta_instance compute_all_applicable_attributes + for qw(get_meta_instance get_all_attributes class_precedence_list get_method_map ); }; @@ -207,8 +193,6 @@ BEGIN { 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') @@ -223,6 +207,12 @@ BEGIN { dies_ok { $meta->superclasses('Foo') } '... set the superclasses'; ok( $meta->$_ , "... ${_} works") - for qw(get_meta_instance compute_all_applicable_attributes + for qw(get_meta_instance get_all_attributes class_precedence_list get_method_map ); } + +{ + Foo->meta->make_immutable; + Bar->meta->make_immutable; + Bar->meta->make_mutable; +}