line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::Collage::TemplatesCollection; |
2
|
2
|
|
|
2
|
|
33
|
use v5.24; |
|
2
|
|
|
|
|
8
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
87
|
|
4
|
|
|
|
|
|
|
{ our $VERSION = '0.001' } |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
13
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
142
|
|
7
|
2
|
|
|
2
|
|
14
|
use JSON::PP qw< decode_json >; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
114
|
|
8
|
2
|
|
|
2
|
|
13
|
use PDF::Collage::Template (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
33
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
9
|
use Moo; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
11
|
|
11
|
2
|
|
|
2
|
|
828
|
use experimental qw< signatures >; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
18
|
|
12
|
2
|
|
|
2
|
|
340
|
no warnings qw< experimental::signatures >; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
79
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
15
|
use namespace::clean; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
25
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has resolver => (is => ro => required => 1 => coerce => \&__resolver); |
17
|
|
|
|
|
|
|
has _selectors => (is => 'lazy'); |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
|
6
|
|
74
|
sub _build__selectors ($self) { |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
9
|
|
20
|
6
|
50
|
|
|
|
29
|
my $list = $self->_resolve(undef, 'list') |
21
|
|
|
|
|
|
|
or croak "cannot ask 'list' to resolver"; |
22
|
|
|
|
|
|
|
my @selectors = |
23
|
9
|
|
|
|
|
63
|
map { s{\A (?: \./)? definitions/ | \.json\z}{}rgmxs } |
24
|
6
|
|
|
|
|
5987
|
grep { m{\A (?: \./)? definitions/.*\.json \z}mxs } |
|
27
|
|
|
|
|
97
|
|
25
|
|
|
|
|
|
|
$list->@*; |
26
|
6
|
|
|
|
|
54
|
return \@selectors; |
27
|
|
|
|
|
|
|
} ## end sub _build__selectors |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
0
|
1
|
0
|
sub contains ($self, $sel) { defined($self->_selector_from($sel)) } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
30
|
|
|
|
|
|
|
|
31
|
21
|
|
|
21
|
1
|
5635
|
sub get ($self, $selector) { |
|
21
|
|
|
|
|
49
|
|
|
21
|
|
|
|
|
38
|
|
|
21
|
|
|
|
|
45
|
|
32
|
21
|
100
|
|
|
|
93
|
$selector = $self->_selector_from($selector) |
33
|
|
|
|
|
|
|
or croak 'invalid selector'; |
34
|
|
|
|
|
|
|
|
35
|
19
|
|
|
|
|
93
|
my $json = $self->_resolve("definitions/$selector.json", 'data'); |
36
|
19
|
|
|
|
|
28165
|
my $definition = decode_json($json); |
37
|
|
|
|
|
|
|
|
38
|
19
|
50
|
|
|
|
78911
|
$definition = { commands => $definition } |
39
|
|
|
|
|
|
|
unless ref($definition) eq 'HASH'; |
40
|
|
|
|
|
|
|
|
41
|
19
|
|
|
|
|
93
|
my $resolver = $self->resolver; |
42
|
|
|
|
|
|
|
$definition->{functions} = { |
43
|
0
|
|
|
0
|
|
0
|
as_data => sub ($key) { $resolver->($key, 'data') }, |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
44
|
49
|
|
|
49
|
|
78
|
as_file => sub ($key, $keep_extension = 1) { |
|
49
|
|
|
|
|
65775
|
|
|
49
|
|
|
|
|
139
|
|
|
49
|
|
|
|
|
106
|
|
45
|
49
|
|
|
|
|
222
|
my $old_name = $resolver->($key, 'file'); |
46
|
49
|
50
|
|
|
|
96450
|
return $old_name unless $keep_extension; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# ensure the extension is there... should I rename the file? |
49
|
49
|
|
|
|
|
395
|
my $extension = $key =~ s{\A.*?\.}{.}rgmxs; |
50
|
49
|
|
|
|
|
106
|
my $elen = length($extension); |
51
|
49
|
100
|
100
|
|
|
419
|
return $old_name |
52
|
|
|
|
|
|
|
if length($old_name) >= $elen |
53
|
|
|
|
|
|
|
&& substr($old_name, -$elen, $elen) eq $extension; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# extension is not there, append it |
56
|
31
|
|
|
|
|
101
|
my $new_name = $old_name . $extension; |
57
|
31
|
|
|
|
|
1682
|
rename $old_name, $new_name; |
58
|
31
|
|
|
|
|
245
|
return $new_name; |
59
|
|
|
|
|
|
|
}, |
60
|
19
|
|
|
|
|
229
|
}; |
61
|
|
|
|
|
|
|
|
62
|
19
|
|
|
|
|
612
|
return PDF::Collage::Template->new($definition); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
12
|
|
|
12
|
1
|
12157
|
sub render ($self, $selector = undef, $data = undef) { |
|
12
|
|
|
|
|
32
|
|
|
12
|
|
|
|
|
32
|
|
|
12
|
|
|
|
|
35
|
|
|
12
|
|
|
|
|
23
|
|
66
|
12
|
100
|
|
|
|
63
|
($selector, $data) = ($data, $selector) if ref($selector); |
67
|
12
|
|
|
|
|
67
|
return $self->get($selector)->render($data); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
25
|
|
|
25
|
|
50
|
sub _resolve ($self, $key, $type) { $self->resolver->($key, $type) } |
|
25
|
|
|
|
|
49
|
|
|
25
|
|
|
|
|
42
|
|
|
25
|
|
|
|
|
41
|
|
|
25
|
|
|
|
|
43
|
|
|
25
|
|
|
|
|
151
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# coercion function to get a Data::Resolver CDDE reference back |
73
|
6
|
|
|
6
|
|
1945
|
sub __resolver ($candidate) { |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
15
|
|
74
|
6
|
50
|
|
|
|
127
|
return $candidate if ref($candidate) eq 'CODE'; |
75
|
0
|
|
|
|
|
0
|
require Data::Resolver; |
76
|
0
|
|
|
|
|
0
|
return Data::Resolver::generate($candidate); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
21
|
|
|
21
|
|
75
|
sub _selector_from ($self, $selector) { |
|
21
|
|
|
|
|
46
|
|
|
21
|
|
|
|
|
38
|
|
|
21
|
|
|
|
|
45
|
|
80
|
21
|
|
|
|
|
575
|
my $sels = $self->_selectors; |
81
|
21
|
100
|
66
|
|
|
316
|
$selector //= $sels->[0] if $sels->@* == 1; |
82
|
21
|
100
|
|
|
|
85
|
return undef unless defined $selector; |
83
|
20
|
|
|
|
|
57
|
my @candidates = grep { $selector eq $_ } $sels->@*; |
|
32
|
|
|
|
|
119
|
|
84
|
20
|
100
|
|
|
|
112
|
return @candidates ? $candidates[0] : undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
6
|
|
|
6
|
1
|
3718
|
sub selectors ($self) { $self->_selectors->@* } |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
146
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |