line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Context::Preserve; |
2
|
2
|
|
|
2
|
|
43844
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
3
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
51
|
|
4
|
2
|
|
|
2
|
|
10
|
use Carp; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
190
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
10
|
use base 'Exporter'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
674
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw(preserve_context); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub preserve_context(&@) { |
12
|
9
|
|
|
9
|
1
|
884
|
my $orig = shift; |
13
|
9
|
|
|
|
|
59
|
my %args = @_; |
14
|
|
|
|
|
|
|
|
15
|
9
|
|
|
|
|
12
|
my $replace = $args{replace}; |
16
|
9
|
|
|
|
|
11
|
my $after = $args{after}; |
17
|
|
|
|
|
|
|
|
18
|
9
|
100
|
100
|
|
|
62
|
croak 'need an "after" or "replace" coderef' |
19
|
|
|
|
|
|
|
unless $replace || $after; |
20
|
|
|
|
|
|
|
|
21
|
8
|
50
|
|
|
|
24
|
if(!defined wantarray){ |
|
|
100
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
$orig->(); |
23
|
0
|
0
|
|
|
|
0
|
if($after){ |
24
|
0
|
|
|
|
|
0
|
$after->(); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
else { |
27
|
0
|
|
|
|
|
0
|
$replace->(); |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
0
|
return; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
elsif(wantarray){ |
32
|
4
|
|
|
|
|
8
|
my @result = $orig->(); |
33
|
4
|
100
|
|
|
|
28
|
if($after){ |
34
|
3
|
|
|
|
|
7
|
my @ignored = $after->(@result); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
1
|
|
|
|
|
3
|
@result = $replace->(@result); |
38
|
|
|
|
|
|
|
} |
39
|
4
|
|
|
|
|
51
|
return @result; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
4
|
|
|
|
|
9
|
my $result = $orig->(); |
43
|
4
|
100
|
|
|
|
24
|
if($after){ |
44
|
3
|
|
|
|
|
7
|
my $ignored = $after->($result); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
else { |
47
|
1
|
|
|
|
|
5
|
$result = $replace->($result); |
48
|
|
|
|
|
|
|
} |
49
|
4
|
|
|
|
|
35
|
return $result; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
__END__ |