line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lazy::Bool::Cached; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
38566
|
use 5.010000; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
130
|
|
4
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
5
|
2
|
|
|
2
|
|
50
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
60
|
|
6
|
2
|
|
|
2
|
|
24
|
use base 'Lazy::Bool'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
983
|
|
7
|
2
|
|
|
2
|
|
19
|
use Exporter 'import'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
568
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw(lzbc); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub lzbc(&) { |
13
|
3
|
|
|
3
|
1
|
3038
|
my $code = shift; |
14
|
3
|
|
|
|
|
16
|
__PACKAGE__->new($code); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
109
|
|
|
109
|
1
|
27127
|
my ( $type, $code ) = @_; |
19
|
|
|
|
|
|
|
|
20
|
109
|
|
66
|
|
|
353
|
my $klass = ref($type) || $type; |
21
|
|
|
|
|
|
|
|
22
|
109
|
100
|
|
2
|
|
281
|
my $ref = ( ref($code) eq 'CODE' ) ? $code : sub { $code }; |
|
2
|
|
|
|
|
12
|
|
23
|
|
|
|
|
|
|
|
24
|
109
|
|
|
|
|
687
|
bless { |
25
|
|
|
|
|
|
|
code => $ref, |
26
|
|
|
|
|
|
|
cached => undef |
27
|
|
|
|
|
|
|
} => $klass; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
2
|
|
|
2
|
|
17
|
use overload 'bool' => \&_to_bool; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
14
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _to_bool { |
33
|
101
|
|
|
101
|
|
758
|
my ($self) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Yes, we can use this: |
36
|
|
|
|
|
|
|
# $self->{cached} //= $self->{code}->() |
37
|
|
|
|
|
|
|
# but the // operator is only supported from Perl 5.10.0 |
38
|
|
|
|
|
|
|
# And this module will be compatible with old versions |
39
|
|
|
|
|
|
|
|
40
|
101
|
100
|
|
|
|
354
|
$self->{cached} = |
41
|
|
|
|
|
|
|
( defined $self->{cached} ) ? $self->{cached} : $self->{code}->(); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |