X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FClass%2FMOP%2FPackage.pm;h=062706fb32fb68e2e54e77f360033f8908f7626b;hb=21ddc881fd1f14d24ac37a1cefb5677d99d5cc48;hp=92e555eef0d7d16b3b1d1cb3104d4ffa456fc3ab;hpb=9520ee8e1c75504698112b729c8f5e637931c8fd;p=gitmo%2FMoose.git diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index 92e555e..062706f 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -96,18 +96,20 @@ sub create { my ($class, %options) = @_; my $cache_ok = delete $options{cache}; + $options{weaken} = !$cache_ok unless exists $options{weaken}; my $cache_key; if ($cache_ok) { $cache_key = $class->_anon_cache_key(%options); + undef $cache_ok if !defined($cache_key); + } + if ($cache_ok) { if (defined $ANON_PACKAGE_CACHE{$cache_key}) { return $ANON_PACKAGE_CACHE{$cache_key}; } } - $options{weaken} = !$cache_ok unless exists $options{weaken}; - my $package_name = $class->_anon_package_prefix . ++$ANON_SERIAL; my $meta = $class->create($package_name, %options); @@ -259,13 +261,14 @@ looking at and changing that namespace's symbol table. =over 4 -=item B<< Class::MOP::Package->initialize($package_name) >> +=item B<< Class::MOP::Package->initialize($package_name, %options) >> This method creates a new C instance which represents specified package. If an existing metaclass object exists -for the package, that will be returned instead. +for the package, that will be returned instead. No options are valid at the +package level. -=item B<< Class::MOP::Package->reinitialize($package) >> +=item B<< Class::MOP::Package->reinitialize($package, %options) >> This method forcibly removes any existing metaclass for the package before calling C. In contrast to C, you may @@ -274,6 +277,31 @@ a package name as C<$package>. Do not call this unless you know what you are doing. +=item B<< Class::MOP::Package->create($package, %options) >> + +Creates a new C instance which represents the specified +package, and also does some initialization of that package. Currently, this +just does the same thing as C, but is overridden in subclasses, +such as C. + +=item B<< Class::MOP::Package->create_anon(%options) >> + +Creates a new anonymous package. Valid keys for C<%options> are: + +=over 4 + +=item C + +If this is true (the default), the instance stored in C's metaclass +cache will be weakened, so that the anonymous package will be garbage collected +when the returned instance goes out of scope. + +=back + +=item B<< $metapackage->is_anon >> + +Returns true if the package is an anonymous package. + =item B<< $metapackage->name >> This is returns the package's name, as passed to the constructor.