my $meta;
if ($class eq 'Class::MOP::Class') {
no strict 'refs';
- $meta = bless {
- # inherited from Class::MOP::Package
- 'package' => $package_name,
-
- # NOTE:
- # since the following attributes will
- # actually be loaded from the symbol
- # table, and actually bypass the instance
- # entirely, we can just leave these things
- # listed here for reference, because they
- # should not actually have a value associated
- # with the slot.
- 'namespace' => \undef,
- # inherited from Class::MOP::Module
- 'version' => \undef,
- 'authority' => \undef,
- # defined in Class::MOP::Class
- 'superclasses' => \undef,
-
- 'methods' => {},
- 'attributes' => {},
- 'attribute_metaclass' => $options{'attribute_metaclass'} || 'Class::MOP::Attribute',
- 'method_metaclass' => $options{'method_metaclass'} || 'Class::MOP::Method',
- 'instance_metaclass' => $options{'instance_metaclass'} || 'Class::MOP::Instance',
-
- ## uber-private variables
- # NOTE:
- # this starts out as undef so that
- # we can tell the first time the
- # methods are fetched
- # - SL
- '_package_cache_flag' => undef,
- '_meta_instance' => undef,
- } => $class;
+ $meta = $class->_new(%options)
}
else {
# NOTE:
$meta;
}
+sub _new {
+ my ( $class, %options ) = @_;
+ bless {
+ # inherited from Class::MOP::Package
+ 'package' => $options{package},
+
+ # NOTE:
+ # since the following attributes will
+ # actually be loaded from the symbol
+ # table, and actually bypass the instance
+ # entirely, we can just leave these things
+ # listed here for reference, because they
+ # should not actually have a value associated
+ # with the slot.
+ 'namespace' => \undef,
+ # inherited from Class::MOP::Module
+ 'version' => \undef,
+ 'authority' => \undef,
+ # defined in Class::MOP::Class
+ 'superclasses' => \undef,
+
+ 'methods' => {},
+ 'attributes' => {},
+ 'attribute_metaclass' => $options{'attribute_metaclass'} || 'Class::MOP::Attribute',
+ 'method_metaclass' => $options{'method_metaclass'} || 'Class::MOP::Method',
+ 'instance_metaclass' => $options{'instance_metaclass'} || 'Class::MOP::Instance',
+ }, $class;
+}
+
sub reset_package_cache_flag { (shift)->{'_package_cache_flag'} = undef }
sub update_package_cache_flag {
my $self = shift;
{
my $meta = Baz->meta;
is($meta->name, 'Baz', '... checking the Baz metaclass');
- my @orig_keys = sort keys %$meta;
+ my @orig_keys = sort grep { !/^_/ } keys %$meta;
lives_ok {$meta->make_immutable; } '... changed Baz to be immutable';
ok(!$meta->is_mutable, '... our class is no longer mutable');
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;
+ my @new_keys = sort grep { !/^_/ } keys %$meta;
is_deeply(\@orig_keys, \@new_keys, '... no straneous hashkeys');
isa_ok($meta, 'Class::MOP::Class', '... Baz->meta isa Class::MOP::Class');
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_keys = sort grep { !/^_/ } keys %$meta;
my @orig_meths = sort { $a->{name} cmp $b->{name} }
$meta->compute_all_applicable_methods;
ok($meta->is_anon_class, 'We have an anon metaclass');
ok($meta->is_anon_class, '... still marked as an anon class');
my $instance = $meta->new_object;
- my @new_keys = sort keys %$meta;
+ my @new_keys = sort grep { !/^_/ } 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');