line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tie::Hash::Method; |
2
|
2
|
|
|
2
|
|
23245
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
606
|
|
3
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
12
|
use base 'Exporter'; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
328
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Tie::Hash::Method - Tied hash with specific methods overriden by callbacks |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.02 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION= '0.02'; |
17
|
|
|
|
|
|
|
$VERSION= eval $VERSION; # just in case we have a dev release |
18
|
|
|
|
|
|
|
our @EXPORT_OK= qw(tie_hash_method HASH METHOD PRIVATE); |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
15
|
use constant HASH => 0; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
175
|
|
21
|
2
|
|
|
2
|
|
13
|
use constant METHOD => 1; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
220
|
|
22
|
2
|
|
|
2
|
|
12
|
use constant PRIVATE => 2; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
100
|
|
23
|
2
|
|
|
2
|
|
3063
|
use Data::Dumper; |
|
2
|
|
|
|
|
18996
|
|
|
2
|
|
|
|
|
2033
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# not overridable obviously. |
26
|
|
|
|
|
|
|
sub TIEHASH { |
27
|
2
|
|
|
2
|
|
857
|
my $class= shift; |
28
|
2
|
|
|
|
|
10
|
my %opts= @_; |
29
|
|
|
|
|
|
|
#die Dumper |
30
|
2
|
|
|
|
|
10
|
bless [ |
31
|
|
|
|
|
|
|
{}, #HASH |
32
|
4
|
|
|
|
|
14
|
+{ map { $_ => $opts{$_} } grep {$_ eq uc($_) } keys %opts }, #METHOD |
|
2
|
|
|
|
|
16
|
|
33
|
2
|
|
|
|
|
9
|
+{ map { $_ => $opts{$_} } grep {$_ ne uc($_) } keys %opts }, #PRIVATE |
|
4
|
|
|
|
|
12
|
|
34
|
|
|
|
|
|
|
], $class; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub FETCH { |
38
|
8
|
100
|
|
8
|
|
142
|
if ( my $cb= $_[0][METHOD]->{FETCH} ) { |
39
|
7
|
|
|
|
|
18
|
return $cb->(@_); |
40
|
|
|
|
|
|
|
} else { |
41
|
1
|
|
|
|
|
6
|
return $_[0][HASH]->{ $_[1] }; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub STORE { |
46
|
6
|
100
|
|
6
|
|
698
|
if ( my $cb= $_[0][METHOD]->{STORE} ) { |
47
|
1
|
|
|
|
|
4
|
return $cb->(@_); |
48
|
|
|
|
|
|
|
} else { |
49
|
5
|
|
|
|
|
25
|
return $_[0][HASH]->{ $_[1] }= $_[2]; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub EXISTS { |
54
|
0
|
0
|
|
0
|
|
0
|
if ( my $cb= $_[0][METHOD]->{EXISTS} ) { |
55
|
0
|
|
|
|
|
0
|
return $cb->(@_); |
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
|
|
|
|
0
|
exists $_[0][HASH]->{ $_[1] }; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub DELETE { |
62
|
1
|
50
|
|
1
|
|
626
|
if ( my $cb= $_[0][METHOD]->{DELETE} ) { |
63
|
0
|
|
|
|
|
0
|
return $cb->(@_); |
64
|
|
|
|
|
|
|
} else { |
65
|
1
|
|
|
|
|
6
|
delete $_[0][HASH]->{ $_[1] }; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub FIRSTKEY { |
71
|
2
|
50
|
|
2
|
|
13
|
if ( my $cb= $_[0][METHOD]->{FIRSTKEY} ) { |
72
|
0
|
|
|
|
|
0
|
return $cb->(@_); |
73
|
|
|
|
|
|
|
} else { |
74
|
|
|
|
|
|
|
# reset iterator |
75
|
2
|
|
|
|
|
4
|
my $val= scalar keys %{ $_[0][HASH] }; |
|
2
|
|
|
|
|
5
|
|
76
|
2
|
|
|
|
|
3
|
return each %{ $_[0][HASH] }; |
|
2
|
|
|
|
|
10
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub NEXTKEY { |
81
|
8
|
50
|
|
8
|
|
18
|
if ( my $cb= $_[0][METHOD]->{NEXTKEY} ) { |
82
|
0
|
|
|
|
|
0
|
return $cb->(@_); |
83
|
|
|
|
|
|
|
} else { |
84
|
8
|
|
|
|
|
8
|
return each %{ $_[0][HASH] }; |
|
8
|
|
|
|
|
29
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub CLEAR { |
90
|
0
|
0
|
|
0
|
|
0
|
if ( my $cb= $_[0][METHOD]->{CLEAR} ) { |
91
|
0
|
|
|
|
|
0
|
return $cb->(@_); |
92
|
|
|
|
|
|
|
} else { |
93
|
0
|
|
|
|
|
0
|
return %{ $_[0][HASH] }= (); |
|
0
|
|
|
|
|
0
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub SCALAR { |
98
|
0
|
0
|
|
0
|
|
0
|
if ( my $cb= $_[0][METHOD]->{SCALAR} ) { |
99
|
0
|
|
|
|
|
0
|
return $cb->(@_); |
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
|
|
|
|
0
|
return scalar %{ $_[0][HASH] }; |
|
0
|
|
|
|
|
0
|
|
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub methods { |
106
|
0
|
|
|
0
|
1
|
0
|
return grep { $_ ne 'hash' } keys %{ $_[0][METHOD] }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
0
|
1
|
0
|
sub method_hash : lvalue { $_[0][METHOD] } |
110
|
|
|
|
|
|
|
|
111
|
13
|
|
|
13
|
1
|
80
|
sub base_hash : lvalue { $_[0][HASH] } |
112
|
0
|
|
|
0
|
1
|
0
|
sub h : lvalue { $_[0][HASH] } |
113
|
4
|
|
|
4
|
1
|
867
|
sub private_hash : lvalue { $_[0][PRIVATE] } |
114
|
0
|
|
|
0
|
1
|
|
sub p : lvalue { $_[0][PRIVATE] } |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub hash_overload { |
117
|
0
|
|
|
0
|
1
|
|
tie my %hash, __PACKAGE__, @_; |
118
|
0
|
|
|
|
|
|
return \%hash; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; #make require happy |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
__END__ |