From: Jesse Luehrs Date: Wed, 22 Sep 2010 18:17:28 +0000 (-0500) Subject: use get_or_add_package_symbol where appropriate X-Git-Tag: 1.09~44 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e40935996d0c20aa345a46d996b76e771d885400;p=gitmo%2FClass-MOP.git use get_or_add_package_symbol where appropriate --- diff --git a/Changes b/Changes index 9fc1ab7..9fd2a46 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,10 @@ Revision history for Perl extension Class-MOP. + [OTHER] + + * Use get_or_add_package_symbol when we intend for it to autovivify, in + preparation for changes in Package::Stash. (doy) + 1.08 Mon, Sep 13, 2010 [BUG FIXES] diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 2eb9312..67d903b 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -763,7 +763,7 @@ sub get_all_attributes { sub superclasses { my $self = shift; - my $isa = $self->get_package_symbol( + my $isa = $self->get_or_add_package_symbol( { sigil => '@', type => 'ARRAY', name => 'ISA' } ); if (@_) { diff --git a/lib/Class/MOP/Module.pm b/lib/Class/MOP/Module.pm index fb1b2b9..7a8b943 100644 --- a/lib/Class/MOP/Module.pm +++ b/lib/Class/MOP/Module.pm @@ -33,12 +33,12 @@ sub _new { sub version { my $self = shift; - ${$self->get_package_symbol({ sigil => '$', type => 'SCALAR', name => 'VERSION' })}; + ${$self->get_or_add_package_symbol({ sigil => '$', type => 'SCALAR', name => 'VERSION' })}; } sub authority { my $self = shift; - ${$self->get_package_symbol({ sigil => '$', type => 'SCALAR', name => 'AUTHORITY' })}; + ${$self->get_or_add_package_symbol({ sigil => '$', type => 'SCALAR', name => 'AUTHORITY' })}; } sub identifier { diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index fa60c6b..de027ae 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -123,6 +123,11 @@ sub get_package_symbol { $self->_package_stash->get_package_symbol(@_); } +sub get_or_add_package_symbol { + my $self = shift; + $self->_package_stash->get_or_add_package_symbol(@_); +} + sub remove_package_symbol { my $self = shift; $self->_package_stash->remove_package_symbol(@_); @@ -191,6 +196,12 @@ Given a variable name, this method returns the variable as a reference or undef if it does not exist. The C<$variable_name> must contain a leading sigil. +=item B<< $metapackage->get_or_add_package_symbol($variable_name) >> + +Given a variable name, this method returns the variable as a reference. +If it does not exist, a default value will be generated if possible. The +C<$variable_name> must contain a leading sigil. + =item B<< $metapackage->has_package_symbol($variable_name) >> Returns true if there is a package variable defined for diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index e5e1bed..daf602d 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -31,7 +31,8 @@ my @class_mop_package_methods = qw( name namespace - add_package_symbol get_package_symbol has_package_symbol remove_package_symbol + add_package_symbol get_package_symbol has_package_symbol + remove_package_symbol get_or_add_package_symbol list_all_package_symbols get_all_package_symbols remove_package_glob _package_stash