6 use Test::More tests => 34;
10 use_ok('Class::MOP', ':universal');
17 ok(!defined($Foo::{foo}), '... the %foo slot has not been created yet');
18 ok(!Foo->meta->has_package_variable('%foo'), '... the meta agrees');
21 Foo->meta->add_package_variable('%foo' => { one => 1 });
22 } '... created %Foo::foo successfully';
24 ok(defined($Foo::{foo}), '... the %foo slot was created successfully');
25 ok(Foo->meta->has_package_variable('%foo'), '... the meta agrees');
29 ok(exists ${'Foo::foo'}{one}, '... our %foo was initialized correctly');
30 is(${'Foo::foo'}{one}, 1, '... our %foo was initialized correctly');
33 my $foo = Foo->meta->get_package_variable('%foo');
34 is_deeply({ one => 1 }, $foo, '... got the right package variable back');
40 is(\%{'Foo::foo'}, Foo->meta->get_package_variable('%foo'), '... our %foo is the same as the metas');
42 ok(exists ${'Foo::foo'}{two}, '... our %foo was updated correctly');
43 is(${'Foo::foo'}{two}, 2, '... our %foo was updated correctly');
46 ok(!defined($Foo::{bar}), '... the @bar slot has not been created yet');
49 Foo->meta->add_package_variable('@bar' => [ 1, 2, 3 ]);
50 } '... created @Foo::bar successfully';
52 ok(defined($Foo::{bar}), '... the @bar slot was created successfully');
56 is(scalar @{'Foo::bar'}, 3, '... our @bar was initialized correctly');
57 is(${'Foo::bar'}[1], 2, '... our @bar was initialized correctly');
60 # now without initial value
62 ok(!defined($Foo::{baz}), '... the %baz slot has not been created yet');
65 Foo->meta->add_package_variable('%baz');
66 } '... created %Foo::baz successfully';
68 ok(defined($Foo::{baz}), '... the %baz slot was created successfully');
72 ${'Foo::baz'}{one} = 1;
74 ok(exists ${'Foo::baz'}{one}, '... our %baz was initialized correctly');
75 is(${'Foo::baz'}{one}, 1, '... our %baz was initialized correctly');
78 ok(!defined($Foo::{bling}), '... the @bling slot has not been created yet');
81 Foo->meta->add_package_variable('@bling');
82 } '... created @Foo::bling successfully';
84 ok(defined($Foo::{bling}), '... the @bling slot was created successfully');
88 is(scalar @{'Foo::bling'}, 0, '... our @bling was initialized correctly');
89 ${'Foo::bling'}[1] = 2;
90 is(${'Foo::bling'}[1], 2, '... our @bling was assigned too correctly');
94 Foo->meta->remove_package_variable('%foo');
95 } '... removed %Foo::foo successfully';
97 ok(!defined($Foo::{foo}), '... the %foo slot was removed successfully');
102 Foo->meta->add_package_variable('bar');
103 } '... no sigil for bar';
106 Foo->meta->remove_package_variable('bar');
107 } '... no sigil for bar';
110 Foo->meta->get_package_variable('bar');
111 } '... no sigil for bar';
114 Foo->meta->has_package_variable('bar');
115 } '... no sigil for bar';
119 Foo->meta->get_package_variable('@.....bar');
120 } '... could not fetch variable';