be used by Moose::Meta::Method::Constructor.
- Make the behaviour of of get_all_package_symbols (and
therefore get_method_map) consistent for stub methods. Report
and test by Goro Fuji (rt.cpan.org #41255). (Florian Ragwitz)
+ * Class::MOP::Immutable
+ - Added a new attribute, inlined_constructor, which is true if
+ the constructor was inlined.
0.71 Wed November 26, 2008
* Class::MOP::Class
'metaclass' => $metaclass,
'options' => $options,
'immutable_metaclass' => undef,
+ 'inlined_constructor' => 0,
);
return $self;
sub metaclass { (shift)->{'metaclass'} }
sub options { (shift)->{'options'} }
+sub inlined_constructor { (shift)->{'inlined_constructor'} }
sub create_immutable_metaclass {
my $self = shift;
name => $options->{constructor_name},
);
- $metaclass->add_method( $options->{constructor_name} => $constructor )
- if $options->{replace_constructor} or $constructor->can_be_inlined;
+ if ( $options->{replace_constructor} or $constructor->can_be_inlined ) {
+ $metaclass->add_method( $options->{constructor_name} => $constructor );
+ $self->{inlined_constructor} = 1;
+ }
}
sub _inline_destructor {
# 14:27 <@stevan> so I am not worried
if ($options{inline_constructor} && $immutable->has_method($options{constructor_name})) {
my $constructor_class = $options{constructor_class} || 'Class::MOP::Method::Constructor';
- $immutable->remove_method( $options{constructor_name} )
- if blessed($immutable->get_method($options{constructor_name})) eq $constructor_class;
+
+ if ( blessed($immutable->get_method($options{constructor_name})) eq $constructor_class ) {
+ $immutable->remove_method( $options{constructor_name} );
+ $self->{inlined_constructor} = 0;
+ }
}
}
the immutable process. C<%options> should be the same options that were
given to make_metaclass_immutable.
+=item B<inlined_constructor>
+
=back
=head1 AUTHORS
use strict;
use warnings;
-use Test::More tests => 84;
+use Test::More tests => 86;
use Test::Exception;
use Class::MOP;
my $immutable_metaclass = $transformer->immutable_metaclass;
is($transformer->metaclass, $meta, '... transformer has correct metaclass');
+ ok(!$transformer->inlined_constructor, '... transformer says it did not inline the constructor');
ok($immutable_metaclass->is_anon_class, '... immutable_metaclass is an anonymous class');
#I don't understand why i need to ->meta here...
$meta->make_immutable();
} '... changed Foo to be immutable';
+ ok($transformer->inlined_constructor, '... transformer says it did inline the constructor');
is($transformer, $meta->get_immutable_transformer, '... immutable transformer cache works');
ok(!$meta->make_immutable, '... make immutable now returns nothing');
use strict;
use warnings;
-use Test::More tests => 111;
+use Test::More tests => 113;
use Test::Exception;
use Scalar::Util;
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');
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');