X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FClass.pm;h=2ac726eed7218e8f7b404b373b2c0df6df818da1;hb=0bfc85b88523ddd75e0868d6ec1244f4365bda07;hp=33ed1e9ffc470f5ad8bed653a1ba6bfcfec3b418;hpb=712ecd187f27b90f67f332cc95905cb9567aa582;p=gitmo%2FClass-MOP.git diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 33ed1e9..2ac726e 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -54,8 +54,8 @@ sub reinitialize { # normal &construct_instance. sub construct_class_instance { my $class = shift; - my %options = @_; - my $package_name = $options{'package'}; + my $options = @_ == 1 ? $_[0] : {@_}; + my $package_name = $options->{package}; (defined $package_name && $package_name) || confess "You must pass a package name"; # NOTE: @@ -82,47 +82,14 @@ sub construct_class_instance { 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: # it is safe to use meta here because # class will always be a subclass of # Class::MOP::Class, which defines meta - $meta = $class->meta->construct_instance(%options) + $meta = $class->meta->construct_instance($options) } # and check the metaclass compatibility @@ -138,6 +105,37 @@ sub construct_class_instance { $meta; } +sub _new { + my $class = shift; + my $options = @_ == 1 ? $_[0] : {@_}; + + 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; @@ -376,11 +374,12 @@ sub new_object { } sub construct_instance { - my ($class, %params) = @_; + my $class = shift; + my $params = @_ == 1 ? $_[0] : {@_}; my $meta_instance = $class->get_meta_instance(); my $instance = $meta_instance->create_instance(); foreach my $attr ($class->compute_all_applicable_attributes()) { - $attr->initialize_instance_slot($meta_instance, $instance, \%params); + $attr->initialize_instance_slot($meta_instance, $instance, $params); } # NOTE: # this will only work for a HASH instance type