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 {
use strict;
use warnings;
-use Test::More tests => 80;
+use Test::More tests => 87;
use Test::Exception;
BEGIN {
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 {
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');
}
use strict;
use warnings;
-use Test::More tests => 80;
+use Test::More tests => 88;
use Test::Exception;
BEGIN {
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 {
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');
}