From: Yuval Kogman Date: Wed, 13 Aug 2008 21:19:56 +0000 (+0000) Subject: immutable constructor for package X-Git-Tag: 0_64_01~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=682655a3e06e41d219d01af74b05e922db316b85;p=gitmo%2FClass-MOP.git immutable constructor for package --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 05291ae..388faef 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -208,15 +208,6 @@ Class::MOP::Package->meta->add_attribute( )) ); -# NOTE: -# use the metaclass to construct the meta-package -# which is a superclass of the metaclass itself :P -Class::MOP::Package->meta->add_method('initialize' => sub { - my $class = shift; - my $package_name = shift; - $class->meta->new_object('package' => $package_name, @_); -}); - ## -------------------------------------------------------- ## Class::MOP::Module diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index 0d6dc1a..10c4622 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -19,9 +19,15 @@ sub initialize { my $package_name = shift; # we hand-construct the class # until we can bootstrap it - no strict 'refs'; - return bless { + $class->_new( 'package' => $package_name, + ); +} + +sub _new { + my ( $class, @args ) = @_; + + bless { # NOTE: # because of issues with the Perl API # to the typeglob in some versions, we @@ -30,7 +36,8 @@ sub initialize { # Ideally we could just store a ref and # it would Just Work, but oh well :\ 'namespace' => \undef, - } => $class; + @args, + }, $class; } # Attributes