line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::StackedMap; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
30791
|
use 5.00503; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
40
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
78
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.03'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
6
|
use Carp qw(croak); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
601
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
4
|
|
|
4
|
1
|
1271
|
my ($pkg, $default) = @_; |
16
|
|
|
|
|
|
|
|
17
|
4
|
|
|
|
|
15
|
my $self = bless [ {} ], $pkg; |
18
|
|
|
|
|
|
|
|
19
|
4
|
100
|
|
|
|
15
|
if (ref $default eq 'HASH') { |
20
|
2
|
|
|
|
|
6
|
%{$self->[-1]} = %$default; |
|
2
|
|
|
|
|
8
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
4
|
|
|
|
|
11
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub delete { |
27
|
2
|
|
|
2
|
1
|
5
|
my ($self, $key) = @_; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
7
|
return delete $self->[-1]->{$key}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub exists { |
33
|
12
|
|
|
12
|
1
|
22
|
my ($self, $key) = @_; |
34
|
|
|
|
|
|
|
|
35
|
12
|
|
|
|
|
48
|
for my $layer (1..@$self) { |
36
|
14
|
100
|
|
|
|
74
|
return -$layer if exists $self->[-$layer]->{$key}; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
|
|
15
|
return 0; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub get { |
43
|
6
|
|
|
6
|
1
|
27
|
my ($self, $key) = @_; |
44
|
|
|
|
|
|
|
|
45
|
6
|
|
|
|
|
17
|
my $layer = $self->exists($key); |
46
|
6
|
100
|
|
|
|
40
|
return $self->[$layer]->{$key} if $layer; |
47
|
|
|
|
|
|
|
|
48
|
1
|
|
|
|
|
5
|
return; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub keys { |
52
|
1
|
|
|
1
|
1
|
6
|
my $self = shift; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
2
|
my %keys; |
55
|
1
|
|
|
|
|
4
|
for my $layer (1..@$self) { |
56
|
2
|
|
|
|
|
3
|
my @kkeys = CORE::keys %{$self->[-$layer]}; |
|
2
|
|
|
|
|
7
|
|
57
|
2
|
|
|
|
|
10
|
@keys{@kkeys} = (1) x scalar @kkeys; |
58
|
|
|
|
|
|
|
} |
59
|
1
|
|
|
|
|
54
|
return CORE::keys %keys; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub top_keys { |
63
|
1
|
|
|
1
|
1
|
648
|
my $self = shift; |
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
|
|
5
|
return CORE::keys %{$self->[1]}; |
|
1
|
|
|
|
|
5
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub pop { |
69
|
4
|
|
|
4
|
1
|
8
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
4
|
100
|
|
|
|
19
|
if (@$self == 1) { |
72
|
1
|
|
|
|
|
198
|
croak "Can't pop single layer stack"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
3
|
|
|
|
|
8
|
return pop @$self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub push { |
79
|
4
|
|
|
4
|
1
|
13
|
my $self = shift; |
80
|
4
|
|
|
|
|
13
|
push @$self, {}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub set { |
84
|
7
|
|
|
7
|
1
|
26
|
my ($self, $key, $value) = @_; |
85
|
|
|
|
|
|
|
|
86
|
7
|
|
|
|
|
26
|
$self->[-1]->{$key} = $value; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
*put = \&set; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub size { |
91
|
3
|
|
|
3
|
1
|
841
|
my $self = shift; |
92
|
3
|
|
|
|
|
23
|
return scalar @$self; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |
96
|
|
|
|
|
|
|
__END__ |