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