line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Util::Guard; |
2
|
|
|
|
|
|
|
|
3
|
76
|
|
|
76
|
|
484
|
use strict; |
|
76
|
|
|
|
|
159
|
|
|
76
|
|
|
|
|
2295
|
|
4
|
76
|
|
|
76
|
|
341
|
use warnings; |
|
76
|
|
|
|
|
174
|
|
|
76
|
|
|
|
|
1862
|
|
5
|
|
|
|
|
|
|
|
6
|
76
|
|
|
76
|
|
480
|
use Carp qw(confess); |
|
76
|
|
|
|
|
153
|
|
|
76
|
|
|
|
|
18065
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.000153'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
58
|
50
|
|
58
|
0
|
16143
|
confess "Can't create a Test2::Util::Guard in void context" unless (defined wantarray); |
12
|
|
|
|
|
|
|
|
13
|
58
|
|
|
|
|
586
|
my $class = shift; |
14
|
58
|
|
50
|
|
|
15478
|
my $handler = shift() || die 'Test2::Util::Guard::new: no handler supplied'; |
15
|
58
|
|
50
|
|
|
902
|
my $ref = ref $handler || ''; |
16
|
|
|
|
|
|
|
|
17
|
58
|
50
|
|
|
|
15626
|
die "Test2::Util::new: invalid handler - expected CODE ref, got: '$ref'" |
18
|
|
|
|
|
|
|
unless ref($handler) eq 'CODE'; |
19
|
|
|
|
|
|
|
|
20
|
58
|
|
33
|
|
|
18525
|
bless [ 0, $handler ], ref $class || $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub dismiss { |
24
|
51
|
|
|
51
|
0
|
483
|
my $self = shift; |
25
|
51
|
50
|
|
|
|
875
|
my $dismiss = @_ ? shift : 1; |
26
|
|
|
|
|
|
|
|
27
|
51
|
|
|
|
|
511
|
$self->[0] = $dismiss; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub DESTROY { |
31
|
52
|
|
|
52
|
|
9039
|
my $self = shift; |
32
|
52
|
|
|
|
|
228
|
my ($dismiss, $handler) = @$self; |
33
|
|
|
|
|
|
|
|
34
|
52
|
100
|
|
|
|
6064
|
$handler->() unless ($dismiss); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |