From: Yuval Kogman Date: Thu, 14 Aug 2008 18:21:45 +0000 (+0000) Subject: accept named params to Package::initialize/reinitialize X-Git-Tag: 0_64_01~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3be6bc1cd2696af20ddf45679ca3cb5930eab371;p=gitmo%2FClass-MOP.git accept named params to Package::initialize/reinitialize --- diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index e5c270b..193934a 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -15,14 +15,20 @@ use base 'Class::MOP::Object'; # creation ... sub initialize { - my $class = shift; - my $package_name = shift; + my ( $class, @args ) = @_; + + unshift @args, "package" if @args % 2; + + my %options = @args; + my $package_name = $options{package}; + + # we hand-construct the class # until we can bootstrap it if ( my $meta = Class::MOP::get_metaclass_by_name($package_name) ) { return $meta; } else { - my $meta = $class->_new({ + my $meta = ( ref $class || $class )->_new({ 'package' => $package_name, }); @@ -33,11 +39,18 @@ sub initialize { } sub reinitialize { - my $class = shift; - my $package_name = shift; + my ( $class, @args ) = @_; + + unshift @args, "package" if @args % 2; + + my %options = @args; + my $package_name = $options{package}; + (defined $package_name && $package_name && !blessed($package_name)) || confess "You must pass a package name and it cannot be blessed"; + Class::MOP::remove_metaclass_by_name($package_name); + $class->initialize('package' => $package_name, @_); }