line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Data::Thunk; |
4
|
|
|
|
|
|
|
BEGIN { |
5
|
1
|
|
|
1
|
|
44217
|
$Data::Thunk::AUTHORITY = 'cpan:NUFFIN'; |
6
|
|
|
|
|
|
|
} |
7
|
|
|
|
|
|
|
BEGIN { |
8
|
1
|
|
|
1
|
|
34
|
$Data::Thunk::VERSION = '0.07'; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
# ABSTRACT: A sneakier Scalar::Defer ;-) |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
9
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
13
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
48
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
630
|
use Data::Thunk::Code; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
16
|
1
|
|
|
1
|
|
707
|
use Data::Thunk::ScalarValue; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
32
|
|
17
|
1
|
|
|
1
|
|
699
|
use Data::Thunk::Object; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
8
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
58
|
|
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
1
|
|
6
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
16
|
use Sub::Exporter -setup => { |
24
|
|
|
|
|
|
|
exports => [qw(lazy lazy_new lazy_object force)], |
25
|
|
|
|
|
|
|
groups => { |
26
|
|
|
|
|
|
|
default => [':all'], |
27
|
|
|
|
|
|
|
}, |
28
|
1
|
|
|
1
|
|
168
|
}; |
|
1
|
|
|
|
|
3
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub lazy (&) { |
31
|
10
|
|
|
10
|
1
|
6313
|
my $thunk = shift; |
32
|
10
|
|
|
|
|
166
|
bless \$thunk, "Data::Thunk::Code"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub lazy_new ($;@) { |
36
|
1
|
|
|
1
|
1
|
6
|
my ( $class, %args ) = @_; |
37
|
1
|
|
50
|
|
|
8
|
my $constructor = delete $args{constructor} || 'new'; |
38
|
1
|
|
50
|
|
|
6
|
my $args = delete $args{args} || []; |
39
|
1
|
|
|
1
|
|
9
|
&lazy_object(sub { $class->$constructor(@$args) }, %args, class => $class); |
|
1
|
|
|
|
|
8
|
|
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub lazy_object (&;@) { |
43
|
1
|
|
|
1
|
1
|
3
|
my ( $thunk, @args ) = @_; |
44
|
1
|
|
|
|
|
10
|
bless { @args, code => $thunk }, "Data::Thunk::Object"; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my ( $vivify_code, $vivify_scalar ) = ( $Data::Thunk::Code::vivify_code, $Data::Thunk::ScalarValue::vivify_scalar ); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub force ($) { |
50
|
3
|
|
|
3
|
1
|
1013
|
my $val = shift; |
51
|
|
|
|
|
|
|
|
52
|
3
|
100
|
|
|
|
17
|
if ( blessed($val) ) { |
53
|
1
|
|
|
1
|
|
913
|
no warnings; # UNIVERSAL::isa |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
143
|
|
54
|
2
|
50
|
|
|
|
13
|
if ( $val->UNIVERSAL::isa('Data::Thunk::Code') ) { # we wanna know what it's *real* class is |
|
|
0
|
|
|
|
|
|
55
|
2
|
|
|
|
|
8
|
return $val->$vivify_code; |
56
|
|
|
|
|
|
|
} elsif ( $val->UNIVERSAL::isa('Data::Thunk::ScalarValue') ) { |
57
|
0
|
|
|
|
|
0
|
return $val->$vivify_scalar; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
4
|
return $val; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
{ |
65
|
|
|
|
|
|
|
package Data::Thunk::NoOverload; |
66
|
|
|
|
|
|
|
BEGIN { |
67
|
1
|
|
|
1
|
|
43
|
$Data::Thunk::NoOverload::AUTHORITY = 'cpan:NUFFIN'; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
BEGIN { |
70
|
1
|
|
|
1
|
|
38
|
$Data::Thunk::NoOverload::VERSION = '0.07'; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
# we temporarily bless into this to avoid overloading |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |