line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Scope::Container; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1019
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
220
|
|
4
|
2
|
|
|
2
|
|
14
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
5
|
2
|
|
|
2
|
|
59
|
use 5.008_001; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
88
|
|
6
|
2
|
|
|
2
|
|
13
|
use Carp qw//; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
53
|
|
7
|
2
|
|
|
2
|
|
11
|
use base qw/Exporter/; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
975
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
10
|
|
|
|
|
|
|
our @EXPORT = qw/start_scope_container scope_container in_scope_container/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $CONTEXT; |
13
|
|
|
|
|
|
|
my $C = 0; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub start_scope_container { |
16
|
11
|
|
|
11
|
1
|
1837
|
my %args = @_; |
17
|
11
|
|
|
|
|
15
|
my $old; |
18
|
11
|
100
|
100
|
|
|
55
|
if ( defined $CONTEXT and !$args{-clear} ) { |
19
|
4
|
|
|
|
|
6
|
$old = $CONTEXT; |
20
|
4
|
|
|
|
|
10
|
$CONTEXT = { map { $_ => $old->{$_} } keys %$old }; |
|
4
|
|
|
|
|
18
|
|
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
else { |
23
|
7
|
|
|
|
|
12
|
$CONTEXT = {}; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
11
|
|
|
|
|
58
|
return bless { c => $C++, old => $old }, __PACKAGE__; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub DESTROY { |
30
|
11
|
|
|
11
|
|
3174
|
my($self) = @_; |
31
|
11
|
100
|
|
|
|
31
|
if ( $self->{c} != --$C ) { |
32
|
2
|
|
|
|
|
221
|
Carp::carp("nested scope_container found, remove all data"); |
33
|
2
|
|
|
|
|
47
|
undef $CONTEXT; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
else { |
36
|
9
|
|
|
|
|
18
|
$CONTEXT = $self->{old}; |
37
|
|
|
|
|
|
|
} |
38
|
11
|
|
|
|
|
46
|
return; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub in_scope_container { |
42
|
2
|
|
|
2
|
1
|
16
|
defined $CONTEXT; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub scope_container { |
46
|
28
|
|
|
28
|
1
|
2506
|
my $key = shift; |
47
|
28
|
50
|
|
|
|
61
|
die "undefined key" if ! defined $key; |
48
|
28
|
100
|
|
|
|
51
|
if ( ! defined $CONTEXT ) { |
49
|
3
|
|
|
|
|
398
|
Carp::carp("scope_container is not initilized"); |
50
|
3
|
|
|
|
|
12
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
25
|
100
|
|
|
|
48
|
if ( @_ ) { |
53
|
10
|
|
|
|
|
37
|
return $CONTEXT->{$key} = shift; |
54
|
|
|
|
|
|
|
} |
55
|
15
|
100
|
|
|
|
34
|
return if ! exists $CONTEXT->{$key}; |
56
|
14
|
|
|
|
|
56
|
$CONTEXT->{$key}; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; |
60
|
|
|
|
|
|
|
__END__ |