6 use Test::More tests => 16;
14 package My::Meta::Package;
22 use base 'Class::MOP::Package';
24 __PACKAGE__->meta->add_attribute(
30 sub add_package_symbol {
31 my ($self, $variable, $initial_value) = @_;
33 my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable);
36 *{$glob} = $initial_value if defined $initial_value;
37 $self->namespace->{$name} = $glob;
41 # No actually package Foo exists :)
42 my $meta = My::Meta::Package->initialize('Foo');
44 isa_ok($meta, 'My::Meta::Package');
45 isa_ok($meta, 'Class::MOP::Package');
47 ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet');
48 ok(!$meta->has_package_symbol('%foo'), '... the meta agrees');
51 $meta->add_package_symbol('%foo' => { one => 1 });
52 } '... the %foo symbol is created succcessfully';
54 ok(!defined($Foo::{foo}), '... the %foo slot has not been created in the actual Foo package');
55 ok($meta->has_package_symbol('%foo'), '... the meta agrees');
57 my $foo = $meta->get_package_symbol('%foo');
58 is_deeply({ one => 1 }, $foo, '... got the right package variable back');
62 is($foo, $meta->get_package_symbol('%foo'), '... our %foo is the same as the metas');
64 ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet');
67 $meta->add_package_symbol('@bar' => [ 1, 2, 3 ]);
68 } '... created @Foo::bar successfully';
70 ok(!defined($Foo::{bar}), '... the @bar slot has still not been created');
72 ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet');
75 $meta->add_package_symbol('%baz');
76 } '... created %Foo::baz successfully';
78 ok(!defined($Foo::{baz}), '... the %baz slot has still not been created');