4 use Test::More tests => 15;
11 package My::Meta::Package;
19 use base 'Class::MOP::Package';
21 __PACKAGE__->meta->add_attribute(
23 reader => 'namespace',
28 sub add_package_symbol {
29 my ($self, $variable, $initial_value) = @_;
31 my ($name, $sigil, $type) = $self->_deconstruct_variable_name($variable);
34 *{$glob} = $initial_value if defined $initial_value;
35 $self->namespace->{$name} = *{$glob};
39 # No actually package Foo exists :)
40 my $meta = My::Meta::Package->initialize('Foo');
42 isa_ok($meta, 'My::Meta::Package');
43 isa_ok($meta, 'Class::MOP::Package');
45 ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet');
46 ok(!$meta->has_package_symbol('%foo'), '... the meta agrees');
49 $meta->add_package_symbol('%foo' => { one => 1 });
50 } '... the %foo symbol is created succcessfully';
52 ok(!defined($Foo::{foo}), '... the %foo slot has not been created in the actual Foo package');
53 ok($meta->has_package_symbol('%foo'), '... the meta agrees');
55 my $foo = $meta->get_package_symbol('%foo');
56 is_deeply({ one => 1 }, $foo, '... got the right package variable back');
60 is($foo, $meta->get_package_symbol('%foo'), '... our %foo is the same as the metas');
62 ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet');
65 $meta->add_package_symbol('@bar' => [ 1, 2, 3 ]);
66 } '... created @Foo::bar successfully';
68 ok(!defined($Foo::{bar}), '... the @bar slot has still not been created');
70 ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet');
73 $meta->add_package_symbol('%baz');
74 } '... created %Foo::baz successfully';
76 ok(!defined($Foo::{baz}), '... the %baz slot has still not been created');