line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test2::Util::Guard; |
2
|
|
|
|
|
|
|
|
3
|
76
|
|
|
76
|
|
514
|
use strict; |
|
76
|
|
|
|
|
188
|
|
|
76
|
|
|
|
|
2280
|
|
4
|
76
|
|
|
76
|
|
397
|
use warnings; |
|
76
|
|
|
|
|
155
|
|
|
76
|
|
|
|
|
2013
|
|
5
|
|
|
|
|
|
|
|
6
|
76
|
|
|
76
|
|
404
|
use Carp qw(confess); |
|
76
|
|
|
|
|
151
|
|
|
76
|
|
|
|
|
19835
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.000155'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
58
|
50
|
|
58
|
0
|
1214
|
confess "Can't create a Test2::Util::Guard in void context" unless (defined wantarray); |
12
|
|
|
|
|
|
|
|
13
|
58
|
|
|
|
|
461
|
my $class = shift; |
14
|
58
|
|
50
|
|
|
16677
|
my $handler = shift() || die 'Test2::Util::Guard::new: no handler supplied'; |
15
|
58
|
|
50
|
|
|
1229
|
my $ref = ref $handler || ''; |
16
|
|
|
|
|
|
|
|
17
|
58
|
50
|
|
|
|
33149
|
die "Test2::Util::new: invalid handler - expected CODE ref, got: '$ref'" |
18
|
|
|
|
|
|
|
unless ref($handler) eq 'CODE'; |
19
|
|
|
|
|
|
|
|
20
|
58
|
|
33
|
|
|
19276
|
bless [ 0, $handler ], ref $class || $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub dismiss { |
24
|
51
|
|
|
51
|
0
|
453
|
my $self = shift; |
25
|
51
|
50
|
|
|
|
927
|
my $dismiss = @_ ? shift : 1; |
26
|
|
|
|
|
|
|
|
27
|
51
|
|
|
|
|
724
|
$self->[0] = $dismiss; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub DESTROY { |
31
|
52
|
|
|
52
|
|
10534
|
my $self = shift; |
32
|
52
|
|
|
|
|
355
|
my ($dismiss, $handler) = @$self; |
33
|
|
|
|
|
|
|
|
34
|
52
|
100
|
|
|
|
6912
|
$handler->() unless ($dismiss); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
1; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
__END__ |