File Coverage

blib/lib/Tie/Hash/Constant.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 17 17 100.0


line stmt bran cond sub pod time code
1             package Tie::Hash::Constant;
2 1     1   742 use strict;
  1         2  
  1         37  
3 1     1   6 use warnings;
  1         1  
  1         104  
4             our $VERSION = 0.01;
5              
6             =head1 NAME
7              
8             Tie::Hash::Constant - make a hash return a constant for all its members
9              
10             =head1 SYNOPSIS
11              
12             use Tie::Hash::Constant;
13             tie my %always_pie, 'Tie::Hash::Constant' => 'PIE!';
14             $always_pie{food} = "salad";
15             print "My favourite food is $always_pie{food}\n"; # prints "My favourite food is PIE!"
16             print "There is no $always_pie{spoon}\n"; # prints "There is no PIE!\n"; !!!
17              
18             =head1 DESCRIPTION
19              
20             Tie::Hash::Constant allows you to define a constant to be returned as
21             all values contained within a hash.
22              
23             It has marginal use as a debugging tool.
24              
25             =cut
26              
27             sub TIEHASH {
28 1     1   379 my $class = shift;
29 1         2 my $constant = shift;
30 1         4 return bless \$constant, $class;
31             }
32              
33             sub FETCH {
34 2     2   232 my $self = shift;
35 2         5 return $$self;
36             }
37              
38 1     1   289 sub STORE {}
39              
40             1;
41             __END__