X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F073_make_mutable.t;h=81143c9b854b02ec5801ef0aa6902579d5532183;hb=afc92ac600289dd8a31b1c4c0a5aa946a2022f1b;hp=0fec326041599a20dba9b7ea55d84907e065b166;hpb=91b73829b31b4035fa1b4a6ad7587a4861961a5d;p=gitmo%2FClass-MOP.git diff --git a/t/073_make_mutable.t b/t/073_make_mutable.t index 0fec326..81143c9 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 => 101; use Test::Exception; use Scalar::Util; -BEGIN { - use_ok('Class::MOP'); -} +use Class::MOP; { package Foo; @@ -53,6 +49,8 @@ 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'); + ok($meta->get_immutable_transformer->inlined_constructor, + '... transformer says it did inline the constructor'); lives_ok { $meta->make_mutable; } '... changed Baz to be mutable'; ok($meta->is_mutable, '... our class is mutable'); @@ -60,6 +58,8 @@ BEGIN { 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'); + ok(!$meta->get_immutable_transformer->inlined_constructor, + '... transformer says it did not inline the constructor'); my @new_keys = sort grep { !/^_/ } keys %$meta; is_deeply(\@orig_keys, \@new_keys, '... no straneous hashkeys'); @@ -69,13 +69,6 @@ BEGIN { 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'); @@ -108,8 +101,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') @@ -133,8 +124,8 @@ BEGIN { 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'); @@ -157,8 +148,8 @@ BEGIN { 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'); @@ -166,10 +157,7 @@ BEGIN { 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'); @@ -207,8 +195,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') @@ -226,3 +212,12 @@ BEGIN { for qw(get_meta_instance compute_all_applicable_attributes class_precedence_list get_method_map ); } + +{ + Foo->meta->make_immutable; + Bar->meta->make_immutable; + Bar->meta->make_mutable; + + isnt( Foo->meta->get_immutable_transformer, Bar->meta->get_immutable_transformer, + 'Foo and Bar should have different immutable transformer objects' ); +}