10 package My::Meta::Package;
18 use base 'Class::MOP::Package';
20 __PACKAGE__->meta->add_attribute(
22 reader => 'namespace',
27 sub add_package_symbol {
28 my ($self, $variable, $initial_value) = @_;
30 my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable);
33 *{$glob} = $initial_value if defined $initial_value;
34 $self->namespace->{$name} = *{$glob};
38 # No actually package Foo exists :)
39 my $meta = My::Meta::Package->initialize('Foo');
41 isa_ok($meta, 'My::Meta::Package');
42 isa_ok($meta, 'Class::MOP::Package');
44 ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet');
45 ok(!$meta->has_package_symbol('%foo'), '... the meta agrees');
48 $meta->add_package_symbol('%foo' => { one => 1 });
49 } '... the %foo symbol is created succcessfully';
51 ok(!defined($Foo::{foo}), '... the %foo slot has not been created in the actual Foo package');
52 ok($meta->has_package_symbol('%foo'), '... the meta agrees');
54 my $foo = $meta->get_package_symbol('%foo');
55 is_deeply({ one => 1 }, $foo, '... got the right package variable back');
59 is($foo, $meta->get_package_symbol('%foo'), '... our %foo is the same as the metas');
61 ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet');
64 $meta->add_package_symbol('@bar' => [ 1, 2, 3 ]);
65 } '... created @Foo::bar successfully';
67 ok(!defined($Foo::{bar}), '... the @bar slot has still not been created');
69 ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet');
72 $meta->add_package_symbol('%baz');
73 } '... created %Foo::baz successfully';
75 ok(!defined($Foo::{baz}), '... the %baz slot has still not been created');