From: Stevan Little Date: Fri, 30 Jun 2006 16:05:01 +0000 (+0000) Subject: rename *_package_variable to *_package_symbol; X-Git-Tag: 0_33~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=58d75218075c1c4d117151122e54eced58f233c1;p=gitmo%2FClass-MOP.git rename *_package_variable to *_package_symbol; --- diff --git a/Changes b/Changes index 8d5e5a8..17e1d80 100644 --- a/Changes +++ b/Changes @@ -117,7 +117,7 @@ Revision history for Perl extension Class-MOP. - added tests and docs for this feature * Class::MOP::Class - - improved &get_package_variable + - improved &get_package_symbol - &version and &superclasses now use it - methods are now blessed into Class::MOP::Method whenever possible diff --git a/examples/C3MethodDispatchOrder.pod b/examples/C3MethodDispatchOrder.pod index 419bb12..7ede35a 100644 --- a/examples/C3MethodDispatchOrder.pod +++ b/examples/C3MethodDispatchOrder.pod @@ -44,14 +44,14 @@ C3MethodDispatchOrder->meta->add_around_method_modifier('initialize' => sub { sub superclasses { my $self = shift; - $self->add_package_variable('@SUPERS' => []) - unless $self->has_package_variable('@SUPERS'); + $self->add_package_symbol('@SUPERS' => []) + unless $self->has_package_symbol('@SUPERS'); if (@_) { my @supers = @_; - @{$self->get_package_variable('@SUPERS')} = @supers; + @{$self->get_package_symbol('@SUPERS')} = @supers; } - @{$self->get_package_variable('@SUPERS')}; + @{$self->get_package_symbol('@SUPERS')}; } sub class_precedence_list { diff --git a/examples/InsideOutClass.pod b/examples/InsideOutClass.pod index 30298a7..438387a 100644 --- a/examples/InsideOutClass.pod +++ b/examples/InsideOutClass.pod @@ -92,25 +92,25 @@ sub create_instance { sub get_slot_value { my ($self, $instance, $slot_name) = @_; - $self->{meta}->get_package_variable('%' . $slot_name)->{refaddr $instance}; + $self->{meta}->get_package_symbol('%' . $slot_name)->{refaddr $instance}; } sub set_slot_value { my ($self, $instance, $slot_name, $value) = @_; - $self->{meta}->get_package_variable('%' . $slot_name)->{refaddr $instance} = $value; + $self->{meta}->get_package_symbol('%' . $slot_name)->{refaddr $instance} = $value; } sub initialize_slot { my ($self, $instance, $slot_name) = @_; - $self->{meta}->add_package_variable(('%' . $slot_name) => {}) - unless $self->{meta}->has_package_variable('%' . $slot_name); - $self->{meta}->get_package_variable('%' . $slot_name)->{refaddr $instance} = undef; + $self->{meta}->add_package_symbol(('%' . $slot_name) => {}) + unless $self->{meta}->has_package_symbol('%' . $slot_name); + $self->{meta}->get_package_symbol('%' . $slot_name)->{refaddr $instance} = undef; } sub is_slot_initialized { my ($self, $instance, $slot_name) = @_; - return 0 unless $self->{meta}->has_package_variable('%' . $slot_name); - return exists $self->{meta}->get_package_variable('%' . $slot_name)->{refaddr $instance} ? 1 : 0; + return 0 unless $self->{meta}->has_package_symbol('%' . $slot_name); + return exists $self->{meta}->get_package_symbol('%' . $slot_name)->{refaddr $instance} ? 1 : 0; } 1; diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index b6fd7f1..bf3c0de 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -1172,7 +1172,7 @@ the creation and inspection of package scoped variables. =over 4 -=item B +=item B Given a C<$variable_name>, which must contain a leading sigil, this method will create that variable within the package which houses the @@ -1180,17 +1180,17 @@ class. It also takes an optional C<$initial_value>, which must be a reference of the same type as the sigil of the C<$variable_name> implies. -=item B +=item B This will return a reference to the package variable in C<$variable_name>. -=item B +=item B Returns true (C<1>) if there is a package variable defined for C<$variable_name>, and false (C<0>) otherwise. -=item B +=item B This will attempt to remove the package variable at C<$variable_name>. diff --git a/lib/Class/MOP/Class/Immutable.pm b/lib/Class/MOP/Class/Immutable.pm index d0a58f6..5d69af6 100644 --- a/lib/Class/MOP/Class/Immutable.pm +++ b/lib/Class/MOP/Class/Immutable.pm @@ -22,8 +22,8 @@ sub remove_method { confess 'Cannot call method "remove_method" on an immutable sub add_attribute { confess 'Cannot call method "add_attribute" on an immutable instance' } sub remove_attribute { confess 'Cannot call method "remove_attribute" on an immutable instance' } -sub add_package_variable { confess 'Cannot call method "add_package_variable" on an immutable instance' } -sub remove_package_variable { confess 'Cannot call method "remove_package_variable" on an immutable instance' } +sub add_package_symbol { confess 'Cannot call method "add_package_symbol" on an immutable instance' } +sub remove_package_symbol { confess 'Cannot call method "remove_package_symbol" on an immutable instance' } # NOTE: # superclasses is an accessor, so @@ -96,7 +96,7 @@ to this class. =item B -=item B +=item B =item B @@ -106,7 +106,7 @@ to this class. =item B -=item B +=item B =item B diff --git a/lib/Class/MOP/Module.pm b/lib/Class/MOP/Module.pm index 8bf93b0..697a391 100644 --- a/lib/Class/MOP/Module.pm +++ b/lib/Class/MOP/Module.pm @@ -19,7 +19,7 @@ sub meta { sub version { my $self = shift; - ${$self->get_package_variable('$VERSION')}; + ${$self->get_package_symbol('$VERSION')}; } 1; diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index fb37c78..61ce12d 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -40,7 +40,7 @@ my %SIGIL_MAP = ( '&' => 'CODE', ); -sub add_package_variable { +sub add_package_symbol { my ($self, $variable, $initial_value) = @_; (defined $variable) @@ -59,7 +59,7 @@ sub add_package_variable { *{$self->name . '::' . $name} = $initial_value; } -sub has_package_variable { +sub has_package_symbol { my ($self, $variable) = @_; (defined $variable) || confess "You must pass a variable name"; @@ -77,7 +77,7 @@ sub has_package_variable { } -sub get_package_variable { +sub get_package_symbol { my ($self, $variable) = @_; (defined $variable) || confess "You must pass a variable name"; @@ -95,7 +95,7 @@ sub get_package_variable { } -sub remove_package_variable { +sub remove_package_symbol { my ($self, $variable) = @_; (defined $variable) @@ -127,7 +127,6 @@ sub remove_package_variable { } } - 1; __END__ @@ -152,13 +151,13 @@ Class::MOP::Package - Package Meta Object =item B -=item B +=item B -=item B +=item B -=item B +=item B -=item B +=item B =back diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index 222db9f..685f924 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -34,7 +34,7 @@ my @class_mop_package_methods = qw( name - add_package_variable get_package_variable has_package_variable remove_package_variable + add_package_symbol get_package_symbol has_package_symbol remove_package_symbol ); my @class_mop_module_methods = qw( @@ -256,10 +256,10 @@ is($class_mop_class_meta->get_attribute('$:method_metaclass')->default, is($class_mop_class_meta->name, 'Class::MOP::Class', '... Class::MOP::Class->name'); is($class_mop_class_meta->version, $Class::MOP::Class::VERSION, '... Class::MOP::Class->version'); -ok($class_mop_class_meta->has_package_variable('$VERSION'), '... Class::MOP::Class->has_package_variable($VERSION)'); -is(${$class_mop_class_meta->get_package_variable('$VERSION')}, +ok($class_mop_class_meta->has_package_symbol('$VERSION'), '... Class::MOP::Class->has_package_symbol($VERSION)'); +is(${$class_mop_class_meta->get_package_symbol('$VERSION')}, $Class::MOP::Class::VERSION, - '... Class::MOP::Class->get_package_variable($VERSION)'); + '... Class::MOP::Class->get_package_symbol($VERSION)'); is_deeply( [ $class_mop_class_meta->superclasses ], diff --git a/t/012_package_variables.t b/t/012_package_variables.t index 6c98884..def46f5 100644 --- a/t/012_package_variables.t +++ b/t/012_package_variables.t @@ -16,14 +16,14 @@ BEGIN { } ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet'); -ok(!Foo->meta->has_package_variable('%foo'), '... the meta agrees'); +ok(!Foo->meta->has_package_symbol('%foo'), '... the meta agrees'); lives_ok { - Foo->meta->add_package_variable('%foo' => { one => 1 }); + Foo->meta->add_package_symbol('%foo' => { one => 1 }); } '... created %Foo::foo successfully'; ok(defined($Foo::{foo}), '... the %foo slot was created successfully'); -ok(Foo->meta->has_package_variable('%foo'), '... the meta agrees'); +ok(Foo->meta->has_package_symbol('%foo'), '... the meta agrees'); { no strict 'refs'; @@ -31,14 +31,14 @@ ok(Foo->meta->has_package_variable('%foo'), '... the meta agrees'); is(${'Foo::foo'}{one}, 1, '... our %foo was initialized correctly'); } -my $foo = Foo->meta->get_package_variable('%foo'); +my $foo = Foo->meta->get_package_symbol('%foo'); is_deeply({ one => 1 }, $foo, '... got the right package variable back'); $foo->{two} = 2; { no strict 'refs'; - is(\%{'Foo::foo'}, Foo->meta->get_package_variable('%foo'), '... our %foo is the same as the metas'); + is(\%{'Foo::foo'}, Foo->meta->get_package_symbol('%foo'), '... our %foo is the same as the metas'); ok(exists ${'Foo::foo'}{two}, '... our %foo was updated correctly'); is(${'Foo::foo'}{two}, 2, '... our %foo was updated correctly'); @@ -47,7 +47,7 @@ $foo->{two} = 2; ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet'); lives_ok { - Foo->meta->add_package_variable('@bar' => [ 1, 2, 3 ]); + Foo->meta->add_package_symbol('@bar' => [ 1, 2, 3 ]); } '... created @Foo::bar successfully'; ok(defined($Foo::{bar}), '... the @bar slot was created successfully'); @@ -63,7 +63,7 @@ ok(defined($Foo::{bar}), '... the @bar slot was created successfully'); ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet'); lives_ok { - Foo->meta->add_package_variable('%baz'); + Foo->meta->add_package_symbol('%baz'); } '... created %Foo::baz successfully'; ok(defined($Foo::{baz}), '... the %baz slot was created successfully'); @@ -79,7 +79,7 @@ ok(defined($Foo::{baz}), '... the %baz slot was created successfully'); ok(!defined($Foo::{bling}), '... the @bling slot has not been created yet'); lives_ok { - Foo->meta->add_package_variable('@bling'); + Foo->meta->add_package_symbol('@bling'); } '... created @Foo::bling successfully'; ok(defined($Foo::{bling}), '... the @bling slot was created successfully'); @@ -92,30 +92,30 @@ ok(defined($Foo::{bling}), '... the @bling slot was created successfully'); } lives_ok { - Foo->meta->remove_package_variable('%foo'); + Foo->meta->remove_package_symbol('%foo'); } '... removed %Foo::foo successfully'; -ok(Foo->meta->has_package_variable('%foo'), '... the %foo slot was removed successfully'); +ok(Foo->meta->has_package_symbol('%foo'), '... the %foo slot was removed successfully'); # check some errors dies_ok { - Foo->meta->add_package_variable('bar'); + Foo->meta->add_package_symbol('bar'); } '... no sigil for bar'; dies_ok { - Foo->meta->remove_package_variable('bar'); + Foo->meta->remove_package_symbol('bar'); } '... no sigil for bar'; dies_ok { - Foo->meta->get_package_variable('bar'); + Foo->meta->get_package_symbol('bar'); } '... no sigil for bar'; dies_ok { - Foo->meta->has_package_variable('bar'); + Foo->meta->has_package_symbol('bar'); } '... no sigil for bar'; #dies_ok { -# Foo->meta->get_package_variable('@.....bar'); +# Foo->meta->get_package_symbol('@.....bar'); #} '... could not fetch variable'; diff --git a/t/016_class_errors_and_edge_cases.t b/t/016_class_errors_and_edge_cases.t index a141133..c92ccf4 100644 --- a/t/016_class_errors_and_edge_cases.t +++ b/t/016_class_errors_and_edge_cases.t @@ -183,78 +183,78 @@ BEGIN { { dies_ok { - Class::MOP::Class->add_package_variable(); - } '... add_package_variable dies as expected'; + Class::MOP::Class->add_package_symbol(); + } '... add_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->add_package_variable(''); - } '... add_package_variable dies as expected'; + Class::MOP::Class->add_package_symbol(''); + } '... add_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->add_package_variable('foo'); - } '... add_package_variable dies as expected'; + Class::MOP::Class->add_package_symbol('foo'); + } '... add_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->add_package_variable('&foo'); - } '... add_package_variable dies as expected'; + Class::MOP::Class->add_package_symbol('&foo'); + } '... add_package_symbol dies as expected'; # throws_ok { -# Class::MOP::Class->meta->add_package_variable('@-'); +# Class::MOP::Class->meta->add_package_symbol('@-'); # } qr/^Could not create package variable \(\@\-\) because/, -# '... add_package_variable dies as expected'; +# '... add_package_symbol dies as expected'; } { dies_ok { - Class::MOP::Class->has_package_variable(); - } '... has_package_variable dies as expected'; + Class::MOP::Class->has_package_symbol(); + } '... has_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->has_package_variable(''); - } '... has_package_variable dies as expected'; + Class::MOP::Class->has_package_symbol(''); + } '... has_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->has_package_variable('foo'); - } '... has_package_variable dies as expected'; + Class::MOP::Class->has_package_symbol('foo'); + } '... has_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->has_package_variable('&foo'); - } '... has_package_variable dies as expected'; + Class::MOP::Class->has_package_symbol('&foo'); + } '... has_package_symbol dies as expected'; } { dies_ok { - Class::MOP::Class->get_package_variable(); - } '... get_package_variable dies as expected'; + Class::MOP::Class->get_package_symbol(); + } '... get_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->get_package_variable(''); - } '... get_package_variable dies as expected'; + Class::MOP::Class->get_package_symbol(''); + } '... get_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->get_package_variable('foo'); - } '... get_package_variable dies as expected'; + Class::MOP::Class->get_package_symbol('foo'); + } '... get_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->get_package_variable('&foo'); - } '... get_package_variable dies as expected'; + Class::MOP::Class->get_package_symbol('&foo'); + } '... get_package_symbol dies as expected'; } { dies_ok { - Class::MOP::Class->remove_package_variable(); - } '... remove_package_variable dies as expected'; + Class::MOP::Class->remove_package_symbol(); + } '... remove_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->remove_package_variable(''); - } '... remove_package_variable dies as expected'; + Class::MOP::Class->remove_package_symbol(''); + } '... remove_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->remove_package_variable('foo'); - } '... remove_package_variable dies as expected'; + Class::MOP::Class->remove_package_symbol('foo'); + } '... remove_package_symbol dies as expected'; dies_ok { - Class::MOP::Class->remove_package_variable('&foo'); - } '... remove_package_variable dies as expected'; + Class::MOP::Class->remove_package_symbol('&foo'); + } '... remove_package_symbol dies as expected'; } diff --git a/t/070_immutable_metaclass.t b/t/070_immutable_metaclass.t index 17407c9..40c935c 100644 --- a/t/070_immutable_metaclass.t +++ b/t/070_immutable_metaclass.t @@ -69,8 +69,8 @@ BEGIN { dies_ok { $meta->add_attribute() } '... exception thrown as expected'; dies_ok { $meta->remove_attribute() } '... exception thrown as expected'; - dies_ok { $meta->add_package_variable() } '... exception thrown as expected'; - dies_ok { $meta->remove_package_variable() } '... exception thrown as expected'; + dies_ok { $meta->add_package_symbol() } '... exception thrown as expected'; + dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected'; my @supers; lives_ok { @@ -133,8 +133,8 @@ BEGIN { dies_ok { $meta->add_attribute() } '... exception thrown as expected'; dies_ok { $meta->remove_attribute() } '... exception thrown as expected'; - dies_ok { $meta->add_package_variable() } '... exception thrown as expected'; - dies_ok { $meta->remove_package_variable() } '... exception thrown as expected'; + dies_ok { $meta->add_package_symbol() } '... exception thrown as expected'; + dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected'; my @supers; lives_ok { @@ -197,8 +197,8 @@ BEGIN { dies_ok { $meta->add_attribute() } '... exception thrown as expected'; dies_ok { $meta->remove_attribute() } '... exception thrown as expected'; - dies_ok { $meta->add_package_variable() } '... exception thrown as expected'; - dies_ok { $meta->remove_package_variable() } '... exception thrown as expected'; + dies_ok { $meta->add_package_symbol() } '... exception thrown as expected'; + dies_ok { $meta->remove_package_symbol() } '... exception thrown as expected'; my @supers; lives_ok { diff --git a/t/080_meta_package.t b/t/080_meta_package.t index dfadb78..3a0efbd 100644 --- a/t/080_meta_package.t +++ b/t/080_meta_package.t @@ -18,14 +18,14 @@ BEGIN { } ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet'); -ok(!Foo->meta->has_package_variable('%foo'), '... the meta agrees'); +ok(!Foo->meta->has_package_symbol('%foo'), '... the meta agrees'); lives_ok { - Foo->meta->add_package_variable('%foo' => { one => 1 }); + Foo->meta->add_package_symbol('%foo' => { one => 1 }); } '... created %Foo::foo successfully'; ok(defined($Foo::{foo}), '... the %foo slot was created successfully'); -ok(Foo->meta->has_package_variable('%foo'), '... the meta agrees'); +ok(Foo->meta->has_package_symbol('%foo'), '... the meta agrees'); { no strict 'refs'; @@ -33,14 +33,14 @@ ok(Foo->meta->has_package_variable('%foo'), '... the meta agrees'); is(${'Foo::foo'}{one}, 1, '... our %foo was initialized correctly'); } -my $foo = Foo->meta->get_package_variable('%foo'); +my $foo = Foo->meta->get_package_symbol('%foo'); is_deeply({ one => 1 }, $foo, '... got the right package variable back'); $foo->{two} = 2; { no strict 'refs'; - is(\%{'Foo::foo'}, Foo->meta->get_package_variable('%foo'), '... our %foo is the same as the metas'); + is(\%{'Foo::foo'}, Foo->meta->get_package_symbol('%foo'), '... our %foo is the same as the metas'); ok(exists ${'Foo::foo'}{two}, '... our %foo was updated correctly'); is(${'Foo::foo'}{two}, 2, '... our %foo was updated correctly'); @@ -49,7 +49,7 @@ $foo->{two} = 2; ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet'); lives_ok { - Foo->meta->add_package_variable('@bar' => [ 1, 2, 3 ]); + Foo->meta->add_package_symbol('@bar' => [ 1, 2, 3 ]); } '... created @Foo::bar successfully'; ok(defined($Foo::{bar}), '... the @bar slot was created successfully'); @@ -65,7 +65,7 @@ ok(defined($Foo::{bar}), '... the @bar slot was created successfully'); ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet'); lives_ok { - Foo->meta->add_package_variable('%baz'); + Foo->meta->add_package_symbol('%baz'); } '... created %Foo::baz successfully'; ok(defined($Foo::{baz}), '... the %baz slot was created successfully'); @@ -81,7 +81,7 @@ ok(defined($Foo::{baz}), '... the %baz slot was created successfully'); ok(!defined($Foo::{bling}), '... the @bling slot has not been created yet'); lives_ok { - Foo->meta->add_package_variable('@bling'); + Foo->meta->add_package_symbol('@bling'); } '... created @Foo::bling successfully'; ok(defined($Foo::{bling}), '... the @bling slot was created successfully'); @@ -94,30 +94,30 @@ ok(defined($Foo::{bling}), '... the @bling slot was created successfully'); } lives_ok { - Foo->meta->remove_package_variable('%foo'); + Foo->meta->remove_package_symbol('%foo'); } '... removed %Foo::foo successfully'; -ok(Foo->meta->has_package_variable('%foo'), '... the %foo slot was removed successfully'); +ok(Foo->meta->has_package_symbol('%foo'), '... the %foo slot was removed successfully'); # check some errors dies_ok { - Foo->meta->add_package_variable('bar'); + Foo->meta->add_package_symbol('bar'); } '... no sigil for bar'; dies_ok { - Foo->meta->remove_package_variable('bar'); + Foo->meta->remove_package_symbol('bar'); } '... no sigil for bar'; dies_ok { - Foo->meta->get_package_variable('bar'); + Foo->meta->get_package_symbol('bar'); } '... no sigil for bar'; dies_ok { - Foo->meta->has_package_variable('bar'); + Foo->meta->has_package_symbol('bar'); } '... no sigil for bar'; #dies_ok { -# Foo->meta->get_package_variable('@.....bar'); +# Foo->meta->get_package_symbol('@.....bar'); #} '... could not fetch variable';