6 use Test::More tests => 16;
14 package My::Meta::Package;
22 use base 'Class::MOP::Package';
24 __PACKAGE__->meta->add_attribute(
26 reader => 'namespace',
31 sub add_package_symbol {
32 my ($self, $variable, $initial_value) = @_;
34 my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable);
37 *{$glob} = $initial_value if defined $initial_value;
38 $self->namespace->{$name} = $glob;
42 # No actually package Foo exists :)
43 my $meta = My::Meta::Package->initialize('Foo');
45 isa_ok($meta, 'My::Meta::Package');
46 isa_ok($meta, 'Class::MOP::Package');
48 ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet');
49 ok(!$meta->has_package_symbol('%foo'), '... the meta agrees');
52 $meta->add_package_symbol('%foo' => { one => 1 });
53 } '... the %foo symbol is created succcessfully';
55 ok(!defined($Foo::{foo}), '... the %foo slot has not been created in the actual Foo package');
56 ok($meta->has_package_symbol('%foo'), '... the meta agrees');
58 my $foo = $meta->get_package_symbol('%foo');
59 is_deeply({ one => 1 }, $foo, '... got the right package variable back');
63 is($foo, $meta->get_package_symbol('%foo'), '... our %foo is the same as the metas');
65 ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet');
68 $meta->add_package_symbol('@bar' => [ 1, 2, 3 ]);
69 } '... created @Foo::bar successfully';
71 ok(!defined($Foo::{bar}), '... the @bar slot has still not been created');
73 ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet');
76 $meta->add_package_symbol('%baz');
77 } '... created %Foo::baz successfully';
79 ok(!defined($Foo::{baz}), '... the %baz slot has still not been created');