8 package My::Stash::Manip;
12 use base 'Stash::Manip';
17 $_[0]->{namespace} ||= {}
20 sub add_package_symbol {
21 my ($self, $variable, $initial_value) = @_;
23 my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable);
26 *{$glob} = $initial_value if defined $initial_value;
27 $self->namespace->{$name} = *{$glob};
31 # No actually package Foo exists :)
32 my $foo_stash = My::Stash::Manip->new('Foo');
34 isa_ok($foo_stash, 'My::Stash::Manip');
35 isa_ok($foo_stash, 'Stash::Manip');
37 ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet');
38 ok(!$foo_stash->has_package_symbol('%foo'), '... the foo_stash agrees');
41 $foo_stash->add_package_symbol('%foo' => { one => 1 });
42 } '... the %foo symbol is created succcessfully';
44 ok(!defined($Foo::{foo}), '... the %foo slot has not been created in the actual Foo package');
45 ok($foo_stash->has_package_symbol('%foo'), '... the foo_stash agrees');
47 my $foo = $foo_stash->get_package_symbol('%foo');
48 is_deeply({ one => 1 }, $foo, '... got the right package variable back');
52 is($foo, $foo_stash->get_package_symbol('%foo'), '... our %foo is the same as the foo_stashs');
54 ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet');
57 $foo_stash->add_package_symbol('@bar' => [ 1, 2, 3 ]);
58 } '... created @Foo::bar successfully';
60 ok(!defined($Foo::{bar}), '... the @bar slot has still not been created');
62 ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet');
65 $foo_stash->add_package_symbol('%baz');
66 } '... created %Foo::baz successfully';
68 ok(!defined($Foo::{baz}), '... the %baz slot has still not been created');