6 use Test::More tests => 43;
11 use_ok('Class::MOP::Package');
17 sub meta { Class::MOP::Package->initialize('Foo') }
20 ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet');
21 ok(!Foo->meta->has_package_symbol('%foo'), '... the meta agrees');
24 Foo->meta->add_package_symbol('%foo' => { one => 1 });
25 } '... created %Foo::foo successfully';
27 ok(!Foo->meta->has_package_symbol('$foo'), '... SCALAR shouldnt have been created too');
29 ok(defined($Foo::{foo}), '... the %foo slot was created successfully');
30 ok(Foo->meta->has_package_symbol('%foo'), '... the meta agrees');
34 ok(defined(*{"Foo::foo"}{HASH}), '... the %foo (HASH) slot was created successfully');
36 ok(!defined(*{"Foo::foo"}{SCALAR}), '... but the $foo slot was not created');
37 ok(!Foo->meta->has_package_symbol('$foo'), '... and the meta agrees');
39 ok(!defined(*{"Foo::foo"}{ARRAY}), '... but the @foo slot was not created');
40 ok(!Foo->meta->has_package_symbol('@foo'), '... and the meta agrees');
42 ok(!defined(*{"Foo::foo"}{CODE}), '... but the &foo slot was not created');
43 ok(!Foo->meta->has_package_symbol('&foo'), '... and the meta agrees');
48 ok(exists ${'Foo::foo'}{one}, '... our %foo was initialized correctly');
49 is(${'Foo::foo'}{one}, 1, '... our %foo was initialized correctly');
52 my $foo = Foo->meta->get_package_symbol('%foo');
53 is_deeply({ one => 1 }, $foo, '... got the right package variable back');
59 is(\%{'Foo::foo'}, Foo->meta->get_package_symbol('%foo'), '... our %foo is the same as the metas');
61 ok(exists ${'Foo::foo'}{two}, '... our %foo was updated correctly');
62 is(${'Foo::foo'}{two}, 2, '... our %foo was updated correctly');
65 ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet');
68 Foo->meta->add_package_symbol('@bar' => [ 1, 2, 3 ]);
69 } '... created @Foo::bar successfully';
71 ok(defined($Foo::{bar}), '... the @bar slot was created successfully');
75 is(scalar @{'Foo::bar'}, 3, '... our @bar was initialized correctly');
76 is(${'Foo::bar'}[1], 2, '... our @bar was initialized correctly');
79 # now without initial value
81 ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet');
84 Foo->meta->add_package_symbol('%baz');
85 } '... created %Foo::baz successfully';
87 ok(defined($Foo::{baz}), '... the %baz slot was created successfully');
91 ${'Foo::baz'}{one} = 1;
93 ok(exists ${'Foo::baz'}{one}, '... our %baz was initialized correctly');
94 is(${'Foo::baz'}{one}, 1, '... our %baz was initialized correctly');
97 ok(!defined($Foo::{bling}), '... the @bling slot has not been created yet');
100 Foo->meta->add_package_symbol('@bling');
101 } '... created @Foo::bling successfully';
103 ok(defined($Foo::{bling}), '... the @bling slot was created successfully');
107 is(scalar @{'Foo::bling'}, 0, '... our @bling was initialized correctly');
108 ${'Foo::bling'}[1] = 2;
109 is(${'Foo::bling'}[1], 2, '... our @bling was assigned too correctly');
113 Foo->meta->remove_package_symbol('%foo');
114 } '... removed %Foo::foo successfully';
116 ok(Foo->meta->has_package_symbol('%foo'), '... the %foo slot was removed successfully');
120 ok(!defined(*{"Foo::foo"}{HASH}), '... the %foo slot has been removed successfully');
126 Foo->meta->add_package_symbol('bar');
127 } '... no sigil for bar';
130 Foo->meta->remove_package_symbol('bar');
131 } '... no sigil for bar';
134 Foo->meta->get_package_symbol('bar');
135 } '... no sigil for bar';
138 Foo->meta->has_package_symbol('bar');
139 } '... no sigil for bar';