6 use Test::More tests => 34;
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_variable('%foo'), '... the meta agrees');
24 Foo->meta->add_package_variable('%foo' => { one => 1 });
25 } '... created %Foo::foo successfully';
27 ok(defined($Foo::{foo}), '... the %foo slot was created successfully');
28 ok(Foo->meta->has_package_variable('%foo'), '... the meta agrees');
32 ok(exists ${'Foo::foo'}{one}, '... our %foo was initialized correctly');
33 is(${'Foo::foo'}{one}, 1, '... our %foo was initialized correctly');
36 my $foo = Foo->meta->get_package_variable('%foo');
37 is_deeply({ one => 1 }, $foo, '... got the right package variable back');
43 is(\%{'Foo::foo'}, Foo->meta->get_package_variable('%foo'), '... our %foo is the same as the metas');
45 ok(exists ${'Foo::foo'}{two}, '... our %foo was updated correctly');
46 is(${'Foo::foo'}{two}, 2, '... our %foo was updated correctly');
49 ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet');
52 Foo->meta->add_package_variable('@bar' => [ 1, 2, 3 ]);
53 } '... created @Foo::bar successfully';
55 ok(defined($Foo::{bar}), '... the @bar slot was created successfully');
59 is(scalar @{'Foo::bar'}, 3, '... our @bar was initialized correctly');
60 is(${'Foo::bar'}[1], 2, '... our @bar was initialized correctly');
63 # now without initial value
65 ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet');
68 Foo->meta->add_package_variable('%baz');
69 } '... created %Foo::baz successfully';
71 ok(defined($Foo::{baz}), '... the %baz slot was created successfully');
75 ${'Foo::baz'}{one} = 1;
77 ok(exists ${'Foo::baz'}{one}, '... our %baz was initialized correctly');
78 is(${'Foo::baz'}{one}, 1, '... our %baz was initialized correctly');
81 ok(!defined($Foo::{bling}), '... the @bling slot has not been created yet');
84 Foo->meta->add_package_variable('@bling');
85 } '... created @Foo::bling successfully';
87 ok(defined($Foo::{bling}), '... the @bling slot was created successfully');
91 is(scalar @{'Foo::bling'}, 0, '... our @bling was initialized correctly');
92 ${'Foo::bling'}[1] = 2;
93 is(${'Foo::bling'}[1], 2, '... our @bling was assigned too correctly');
97 Foo->meta->remove_package_variable('%foo');
98 } '... removed %Foo::foo successfully';
100 ok(Foo->meta->has_package_variable('%foo'), '... the %foo slot was removed successfully');
105 Foo->meta->add_package_variable('bar');
106 } '... no sigil for bar';
109 Foo->meta->remove_package_variable('bar');
110 } '... no sigil for bar';
113 Foo->meta->get_package_variable('bar');
114 } '... no sigil for bar';
117 Foo->meta->has_package_variable('bar');
118 } '... no sigil for bar';
122 # Foo->meta->get_package_variable('@.....bar');
123 #} '... could not fetch variable';