line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::DefGen; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
16918
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
47
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
BEGIN { |
7
|
1
|
|
|
1
|
|
4
|
require Exporter; |
8
|
1
|
|
|
|
|
5
|
*import = \&Exporter::import; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
|
|
1
|
our $VERSION = "1.001003"; |
11
|
1
|
|
|
|
|
13
|
our @EXPORT = qw(def); |
12
|
|
|
|
|
|
|
} |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
2
|
use Scalar::Util qw(reftype blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
370
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# to subclass, copy and EXPORT this function |
17
|
21
|
|
|
21
|
0
|
8484
|
sub def (&@) { __PACKAGE__->new(data => shift, @_) } |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub new { |
20
|
21
|
|
|
21
|
0
|
25
|
my $class = shift; |
21
|
21
|
|
|
|
|
38
|
my $self = bless { }, $class; |
22
|
21
|
|
|
|
|
34
|
$self->_init(@_); |
23
|
21
|
|
|
|
|
91
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _init { |
27
|
21
|
|
|
21
|
|
18
|
my $self = shift; |
28
|
21
|
|
|
|
|
18
|
%{ $self } = ( |
|
21
|
|
|
|
|
52
|
|
29
|
|
|
|
|
|
|
data => undef, |
30
|
|
|
|
|
|
|
@_, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
|
0
|
$self->{obj_cloner} = sub { $_[0] } |
34
|
21
|
100
|
|
|
|
117
|
unless UNIVERSAL::isa($self->{obj_cloner}, "CODE"); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub gen { |
38
|
23
|
|
|
23
|
0
|
25
|
my $self = shift; |
39
|
23
|
|
|
|
|
43
|
local $self->{gen_p} = \@_; |
40
|
|
|
|
|
|
|
|
41
|
23
|
50
|
|
|
|
53
|
return $self->_gen($self->{data}) if ref($self->{data}) ne "CODE"; |
42
|
|
|
|
|
|
|
|
43
|
23
|
|
|
|
|
19
|
my @data = @{ $self->_gen([ $self->{data}->(@_) ]) }; |
|
23
|
|
|
|
|
52
|
|
44
|
23
|
|
|
|
|
198
|
return @data[0 .. $#data]; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _gen { |
48
|
95
|
|
|
95
|
|
145
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
95
|
100
|
|
|
|
202
|
if (defined blessed($_[0])) |
51
|
|
|
|
|
|
|
{ |
52
|
15
|
|
|
|
|
53
|
return $_[0]->isa(ref $self) |
53
|
17
|
100
|
|
|
|
84
|
? $_[0]->gen(@{ $self->{gen_p} }) |
54
|
|
|
|
|
|
|
: $self->{obj_cloner}->($_[0]); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
78
|
|
|
|
|
107
|
my $type = reftype($_[0]); |
58
|
78
|
100
|
|
|
|
194
|
$type or return $_[0]; |
59
|
42
|
100
|
|
|
|
55
|
$type eq "HASH" and return { map +($_ => $self->_gen($_[0]->{$_})), keys %{ $_[0] } }; |
|
7
|
|
|
|
|
27
|
|
60
|
35
|
50
|
|
|
|
52
|
$type eq "ARRAY" and return [ map $self->_gen($_), @{ $_[0] } ]; |
|
35
|
|
|
|
|
83
|
|
61
|
0
|
0
|
|
|
|
|
$type eq "SCALAR" and return \${ $_[0] }; |
|
0
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
$type eq "REF" and return \$self->_gen(${ $_[0] }); |
|
0
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return $_[0]; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |