Tie-InSecureHash

 view release on metacpan or  search on metacpan

InSecureHash.pm  view on Meta::CPAN

	{
		carp qq{Tie'ing a securehash directly should never happen in 'fast' mode.\n}.
		     qq{Use Tie::SecureHash::new instead}
	}
	bless {}, $class;
}

sub FETCH	# ($self, $key)
{
	my ($self, $key) = @_;
	my $entry = _access($self,$key,(caller)[0..1]);
	return $$entry if $entry;
	return;
}

sub STORE	# ($self, $key, $value)
{
	my ($self, $key, $value) = @_;
	my $entry = _access($self,$key,(caller)[0..1]);
	return $$entry = $value if $entry;
	return;
}

sub DELETE	# ($self, $key)
{
	my ($self, $key) = @_;
	return _access($self,$key,(caller)[0..1],'DELETE');
}

sub CLEAR	# ($self)
{
	my ($self) = @_;
	my ($caller, $file) = caller;
	my @inaccessibles =
		grep { ! eval { _access($self,$_,$caller,$file); 1 } }
			keys %{$self->{fullkeys}};
	croak "Unable to assign to securehash because the following existing keys\nare inaccessible from package $caller and cannot be deleted:\n" .
		join("\n", map {"\t$_"} @inaccessibles) . "\n "
			if @inaccessibles;
	%{$self} = ();
}

sub EXISTS	# ($self, $key)
{
	my ($self, $key) = @_;
	my @context = (caller)[0..1];
	eval { _access($self,$key,@context); 1 } ? 1 : '';
}

sub FIRSTKEY	# ($self)
{
	my ($self) = @_;
	keys %{$self->{fullkeys}};
	goto &NEXTKEY;
}

sub NEXTKEY	# ($self)
{
	my $self = $_[0];
	my $key;
	my @context = (caller)[0..1];
	while (defined($key = each %{$self->{fullkeys}}))
	{
		last if eval { _access($self,$key,@context) };
	}
	return $key;
}

sub DESTROY	# ($self)
{
	# NOTHING TO DO

test.pl  view on Meta::CPAN

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
{



( run in 0.343 second using v1.01-cache-2.11-cpan-a3c8064c92c )