X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F04-get.t;fp=t%2F04-get.t;h=ebeb8647c4626e25320f71a4d0d7312c9ccd3a65;hb=67b1704808e62f27210fe992df9c45b232fe9d5b;hp=3c4ae4373383b8e1492108db463c9646e859a683;hpb=23093e2990bf64f03ad844e7b08fffa34ead8510;p=gitmo%2FPackage-Stash-PP.git diff --git a/t/04-get.t b/t/04-get.t index 3c4ae43..ebeb864 100644 --- a/t/04-get.t +++ b/t/04-get.t @@ -7,178 +7,60 @@ use Package::Stash; { BEGIN { - my $stash = Package::Stash->new('Hash'); + my $stash = Package::Stash->new('Foo'); my $val = $stash->get_package_symbol('%foo'); is($val, undef, "got nothing yet"); } { no warnings 'void', 'once'; - %Hash::foo; + %Foo::foo; } BEGIN { - my $stash = Package::Stash->new('Hash'); + my $stash = Package::Stash->new('Foo'); my $val = $stash->get_package_symbol('%foo'); is(ref($val), 'HASH', "got something"); $val->{bar} = 1; is_deeply($stash->get_package_symbol('%foo'), {bar => 1}, - "got the right variable"); - is_deeply(\%Hash::foo, {bar => 1}, - "stash has the right variable"); + "got the right variable"); } } { BEGIN { - my $stash = Package::Stash->new('Array'); + my $stash = Package::Stash->new('Bar'); my $val = $stash->get_package_symbol('@foo'); - is($val, undef, "got nothing yet"); + is($val, undef, "got something"); } { no warnings 'void', 'once'; - @Array::foo; + @Bar::foo; } BEGIN { - my $stash = Package::Stash->new('Array'); + my $stash = Package::Stash->new('Bar'); my $val = $stash->get_package_symbol('@foo'); is(ref($val), 'ARRAY', "got something"); push @$val, 1; is_deeply($stash->get_package_symbol('@foo'), [1], - "got the right variable"); - is_deeply(\@Array::foo, [1], - "stash has the right variable"); - } -} - -{ - BEGIN { - my $stash = Package::Stash->new('Scalar'); - my $val = $stash->get_package_symbol('$foo'); - is($val, undef, "got nothing yet"); - } - { - no warnings 'void', 'once'; - $Scalar::foo; - } - BEGIN { - my $stash = Package::Stash->new('Scalar'); - my $val = $stash->get_package_symbol('$foo'); - is(ref($val), 'SCALAR', "got something"); - $$val = 1; - is_deeply($stash->get_package_symbol('$foo'), \1, - "got the right variable"); - is($Scalar::foo, 1, - "stash has the right variable"); - } -} - -{ - BEGIN { - my $stash = Package::Stash->new('Code'); - my $val = $stash->get_package_symbol('&foo'); - is($val, undef, "got nothing yet"); - } - { - no warnings 'void', 'once'; - sub Code::foo { } - } - BEGIN { - my $stash = Package::Stash->new('Code'); - my $val = $stash->get_package_symbol('&foo'); - is(ref($val), 'CODE', "got something"); - is(prototype($val), undef, "got the right variable"); - &Scalar::Util::set_prototype($val, '&'); - is($stash->get_package_symbol('&foo'), $val, - "got the right variable"); - is(prototype($stash->get_package_symbol('&foo')), '&', - "got the right variable"); - is(prototype(\&Code::foo), '&', - "stash has the right variable"); - } -} - -{ - BEGIN { - my $stash = Package::Stash->new('Io'); - my $val = $stash->get_package_symbol('FOO'); - is($val, undef, "got nothing yet"); - } - { - no warnings 'void', 'once'; - package Io; - fileno(FOO); - } - BEGIN { - my $stash = Package::Stash->new('Io'); - my $val = $stash->get_package_symbol('FOO'); - isa_ok($val, 'IO'); - my $str = "foo"; - open $val, '<', \$str; - is(readline($stash->get_package_symbol('FOO')), "foo", - "got the right variable"); - seek($stash->get_package_symbol('FOO'), 0, 0); - { - package Io; - ::isa_ok(*FOO{IO}, 'IO'); - ::is(, "foo", - "stash has the right variable"); - } + "got the right variable"); } } { - my $stash = Package::Stash->new('Hash::Vivify'); + my $stash = Package::Stash->new('Baz'); my $val = $stash->get_or_add_package_symbol('%foo'); is(ref($val), 'HASH', "got something"); $val->{bar} = 1; is_deeply($stash->get_or_add_package_symbol('%foo'), {bar => 1}, - "got the right variable"); - no warnings 'once'; - is_deeply(\%Hash::Vivify::foo, {bar => 1}, - "stash has the right variable"); + "got the right variable"); } { - my $stash = Package::Stash->new('Array::Vivify'); + my $stash = Package::Stash->new('Quux'); my $val = $stash->get_or_add_package_symbol('@foo'); is(ref($val), 'ARRAY', "got something"); push @$val, 1; is_deeply($stash->get_or_add_package_symbol('@foo'), [1], - "got the right variable"); - no warnings 'once'; - is_deeply(\@Array::Vivify::foo, [1], - "stash has the right variable"); -} - -{ - my $stash = Package::Stash->new('Scalar::Vivify'); - my $val = $stash->get_or_add_package_symbol('$foo'); - is(ref($val), 'SCALAR', "got something"); - $$val = 1; - is_deeply($stash->get_or_add_package_symbol('$foo'), \1, - "got the right variable"); - no warnings 'once'; - is($Scalar::Vivify::foo, 1, - "stash has the right variable"); -} - -{ - BEGIN { - my $stash = Package::Stash->new('Io::Vivify'); - my $val = $stash->get_or_add_package_symbol('FOO'); - isa_ok($val, 'IO'); - my $str = "foo"; - open $val, '<', \$str; - is(readline($stash->get_package_symbol('FOO')), "foo", - "got the right variable"); - seek($stash->get_package_symbol('FOO'), 0, 0); - } - { - package Io::Vivify; - no warnings 'once'; - ::isa_ok(*FOO{IO}, 'IO'); - ::is(, "foo", - "stash has the right variable"); - } + "got the right variable"); } done_testing;