Tie-InSecureHash
view release on metacpan or search on metacpan
#! /usr/local/bin/perl -ws
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
######################### We start with some black magic to print on failure.
use 5.005;
BEGIN { $| = 1; print "1..274\n"; }
END {print "not ok 1\n" unless $loaded;}
use Tie::InSecureHash;
$loaded = 1;
@failed = ();
END {print "[Failed test: ", join(", ",@failed), "]\n" if @failed;}
print "ok 1\n";
######################### End of black magic.
$hashref = Tie::InSecureHash->new();
$ok_count = 1;
sub ok($)
{
# print "\t$@" if $@ && $::VERBOSE;
# print "\tUnexpected error at ", (caller)[2], "\n"
# if !$_[0] && !$@ && $::VERBOSE;
# print "not " unless $_[0];
print "ok ", ++$ok_count;
# print "\t($_[0])" if $_[0] && $::VERBOSE;
print "\n";
# push @::failed, $ok_count unless $_[0];
}
sub NB
{
print "\n@_\n" if $::VERBOSE;
}
package Parent;
::NB "CAN'T DECLARE FIELDS WITHOUT CLASS";
::ok not eval { $::hashref->{__private_p} = "invalid" };
::ok not eval { $::hashref->{_protected_p} = "invalid" };
::ok not eval { $::hashref->{public_p} = "invalid" };
::NB "CAN DECLARE FIELDS OF THIS CLASS";
::ok eval { $::hashref->{Parent::__private_p} = "private_p" };
::ok eval { $::hashref->{Parent::_protected_p} = "protected_p" };
::ok eval { $::hashref->{Parent::public_p} = "public_p" };
::NB "CAN DECLARE FIELDS IN A GLOB";
::ok eval { local *hash = $::hashref;
@hash{"Parent::__ambiguous", "Parent::_ambiguous", "Parent::ambiguous"}
= ( "ambiguous_p", "ambiguous_p", "ambiguous_p");
1;
};
::ok eval { $::hashref->{Parent::__ambiguous} = "ambiguous_p" };
::ok eval { $::hashref->{Parent::_ambiguous} = "ambiguous_p" };
::ok eval { $::hashref->{Parent::ambiguous} = "ambiguous_p" };
::NB "CAN'T DECLARE FIELDS OF ANOTHER CLASS";
::ok not eval { $::hashref->{Other::__private_p} = "private_p" };
::ok not eval { $::hashref->{Other::_protected_p} = "protected_p" };
::ok not eval { $::hashref->{Other::public_p} = "public_p" };
::NB "CAN ACCESS ALL FIELDS OF THIS CLASS EXPLICITLY";
::ok eval { $::hashref->{Parent::__private_p} };
::ok eval { $::hashref->{Parent::_protected_p} };
::ok eval { $::hashref->{Parent::public_p} };
::NB "CAN ACCESS ALL FIELDS OF THIS CLASS IMPLICITLY";
::ok eval { $::hashref->{__private_p} };
::ok eval { $::hashref->{_protected_p} };
::ok eval { $::hashref->{public_p} };
::NB "CAN'T ACCESS NON-EXISTENT FIELDS OF THIS CLASS IMPLICITLY";
::ok not eval { $::hashref->{__private_p_ne} };
::ok not eval { $::hashref->{_protected_p_ne} };
::ok not eval { $::hashref->{_public_p_ne} };
::NB "CAN ACCESS NON_EXISTENT FIELDS OF THIS CLASS EXPLICITY (CREATES THEM)";
( run in 3.522 seconds using v1.01-cache-2.11-cpan-524268b4103 )