From: Stevan Little Date: Thu, 10 Aug 2006 21:58:40 +0000 (+0000) Subject: fixed the tests and worked around perls typeglob yuk X-Git-Tag: 0_33~11^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d852f4d231f8ce024f262b95da55c0d4935c05bb;p=gitmo%2FClass-MOP.git fixed the tests and worked around perls typeglob yuk --- diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index 2911d2e..88df8d5 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -95,7 +95,23 @@ sub has_package_symbol { my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable); return 0 unless exists $self->namespace->{$name}; - defined *{$self->namespace->{$name}}{$type} ? 1 : 0; + + # FIXME: + # For some really stupid reason + # a typeglob will have a default + # value of \undef in the SCALAR + # slot, so we need to work around + # this. Which of course means that + # if you put \undef in your scalar + # then this is broken. + + if ($type eq 'SCALAR') { + my $val = *{$self->namespace->{$name}}{$type}; + defined $$val ? 1 : 0; + } + else { + defined *{$self->namespace->{$name}}{$type} ? 1 : 0; + } } sub get_package_symbol { diff --git a/t/012_package_variables.t b/t/012_package_variables.t index 7544d98..9509898 100644 --- a/t/012_package_variables.t +++ b/t/012_package_variables.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 80; +use Test::More tests => 87; use Test::Exception; BEGIN { @@ -190,7 +190,7 @@ is(Foo->meta->get_package_symbol('$foo'), $SCALAR, '... got the right value for ok(!defined(*{"Foo::foo"}{HASH}), '... the %foo slot has been removed successfully'); ok(defined(*{"Foo::foo"}{ARRAY}), '... the @foo slot has NOT been removed'); ok(defined(*{"Foo::foo"}{CODE}), '... the &foo slot has NOT been removed'); - ok(defined(*{"Foo::foo"}{SCALAR}), '... the $foo slot has NOT been removed'); + ok(defined(${"Foo::foo"}), '... the $foo slot has NOT been removed'); } lives_ok { @@ -210,7 +210,25 @@ is(Foo->meta->get_package_symbol('$foo'), $SCALAR, '... got the right value for ok(!defined(*{"Foo::foo"}{HASH}), '... the %foo slot has been removed successfully'); ok(!defined(*{"Foo::foo"}{CODE}), '... the &foo slot has now been removed'); ok(defined(*{"Foo::foo"}{ARRAY}), '... the @foo slot has NOT been removed'); - ok(defined(*{"Foo::foo"}{SCALAR}), '... the $foo slot has NOT been removed'); + ok(defined(${"Foo::foo"}), '... the $foo slot has NOT been removed'); +} + +lives_ok { + Foo->meta->remove_package_symbol('$foo'); +} '... removed $Foo::foo successfully'; + +ok(!Foo->meta->has_package_symbol('$foo'), '... the $foo slot no longer exists'); + +ok(Foo->meta->has_package_symbol('@foo'), '... the @foo slot still exists'); + +is(Foo->meta->get_package_symbol('@foo'), $ARRAY, '... got the right values for @Foo::foo'); + +{ + no strict 'refs'; + ok(!defined(*{"Foo::foo"}{HASH}), '... the %foo slot has been removed successfully'); + ok(!defined(*{"Foo::foo"}{CODE}), '... the &foo slot has now been removed'); + ok(!defined(${"Foo::foo"}), '... the $foo slot has now been removed'); + ok(defined(*{"Foo::foo"}{ARRAY}), '... the @foo slot has NOT been removed'); } diff --git a/t/080_meta_package.t b/t/080_meta_package.t index 547ddda..a300af9 100644 --- a/t/080_meta_package.t +++ b/t/080_meta_package.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 80; +use Test::More tests => 88; use Test::Exception; BEGIN { @@ -185,7 +185,7 @@ is(Foo->meta->get_package_symbol('$foo'), $SCALAR, '... got the right value for ok(!defined(*{"Foo::foo"}{HASH}), '... the %foo slot has been removed successfully'); ok(defined(*{"Foo::foo"}{ARRAY}), '... the @foo slot has NOT been removed'); ok(defined(*{"Foo::foo"}{CODE}), '... the &foo slot has NOT been removed'); - ok(defined(*{"Foo::foo"}{SCALAR}), '... the $foo slot has NOT been removed'); + ok(defined(${"Foo::foo"}), '... the $foo slot has NOT been removed'); } lives_ok { @@ -205,7 +205,25 @@ is(Foo->meta->get_package_symbol('$foo'), $SCALAR, '... got the right value for ok(!defined(*{"Foo::foo"}{HASH}), '... the %foo slot has been removed successfully'); ok(!defined(*{"Foo::foo"}{CODE}), '... the &foo slot has now been removed'); ok(defined(*{"Foo::foo"}{ARRAY}), '... the @foo slot has NOT been removed'); - ok(defined(*{"Foo::foo"}{SCALAR}), '... the $foo slot has NOT been removed'); + ok(defined(${"Foo::foo"}), '... the $foo slot has NOT been removed'); +} + +lives_ok { + Foo->meta->remove_package_symbol('$foo'); +} '... removed $Foo::foo successfully'; + +ok(!Foo->meta->has_package_symbol('$foo'), '... the $foo slot no longer exists'); + +ok(Foo->meta->has_package_symbol('@foo'), '... the @foo slot still exists'); + +is(Foo->meta->get_package_symbol('@foo'), $ARRAY, '... got the right values for @Foo::foo'); + +{ + no strict 'refs'; + ok(!defined(*{"Foo::foo"}{HASH}), '... the %foo slot has been removed successfully'); + ok(!defined(*{"Foo::foo"}{CODE}), '... the &foo slot has now been removed'); + ok(!defined(${"Foo::foo"}), '... the $foo slot has now been removed'); + ok(defined(*{"Foo::foo"}{ARRAY}), '... the @foo slot has NOT been removed'); }