File Coverage

blib/lib/Acme/DarmstadtPM/TieHash.pm
Criterion Covered Total %
statement 22 49 44.9
branch 3 16 18.7
condition n/a
subroutine 5 11 45.4
pod n/a
total 30 76 39.4


line stmt bran cond sub pod time code
1             package Acme::DarmstadtPM::TieHash;
2              
3             # ABSTRACT: a module that shows that Perl can do all the Ruby things ;-)
4              
5 1     1   729 use strict;
  1         2  
  1         29  
6 1     1   5 use warnings;
  1         1  
  1         28  
7              
8 1     1   773 use Tie::ListKeyedHash;
  1         2546  
  1         425  
9              
10             our $VERSION = '0.4';
11              
12             sub TIEHASH{
13 1     1   338 my ($class,$code) = @_;
14            
15            
16 1         2 my $self = {};
17 1         2 my %hash;
18 1         2 bless $self,$class;
19            
20 1         3 tie %hash,'Tie::ListKeyedHash';
21 1         14 $self->{HASH} = \%hash;
22 1         2 $self->{CODE} = $code;
23            
24 1         3 return $self;
25             }
26              
27             sub FETCH{
28 3     3   652 my ($self,$key) = @_;
29            
30 3 50       9 if (not ref $key) {
31 0         0 $key = [split(/$;/,$key)];
32             }
33            
34 3 100       11 unless(exists $self->{HASH}->{$key}){
35 2         48 $self->{HASH}->{$key} = $self->{CODE}->(@$key);
36             }
37            
38 3         60 return $self->{HASH}->{$key};
39             }
40              
41             sub STORE{
42 0     0     my ($self,$key,$value) = @_;
43            
44 0 0         if (not ref $key) {
45 0           $key = [split(/$;/,$key)];
46             }
47            
48 0           $self->{HASH}->{$key} = $value;
49             }
50              
51             sub DELETE{
52 0     0     my ($self,$key) = @_;
53              
54 0 0         if (not ref $key) {
55 0           $key = [split(/$;/,$key)];
56             }
57            
58 0           delete $self->{HASH}->{$key};
59             }
60              
61             sub EXISTS{
62 0     0     my ($self,$key) = @_;
63              
64 0 0         if (not ref $key) {
65 0           $key = [split(/$;/,$key)];
66             }
67              
68 0 0         return exists $self->{HASH}->{$key} ? 1 : 0;
69             }
70              
71             sub CLEAR{
72 0     0     my ($self) = @_;
73 0           $self->{HASH} = ();
74             }
75              
76             sub FIRSTKEY{
77 0     0     my ($self) = @_;
78            
79 0           my $a = keys %{$self->{HASH}};
  0            
80 0           my $key = scalar each %{$self->{HASH}};
  0            
81 0 0         return if (not defined $key);
82 0           return [$key];
83             }
84              
85             sub NEXTKEY {
86 0     0     my ($self,$last_key) = @_;
87 0           my $key = scalar each %{$self->{HASH}};
  0            
88 0 0         return if (not defined $key);
89 0           return [$key];
90             }
91              
92             1;
93              
94             __END__