line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PDF::Collage::TemplatesCollection; |
2
|
2
|
|
|
2
|
|
27
|
use v5.24; |
|
2
|
|
|
|
|
7
|
|
3
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
80
|
|
4
|
|
|
|
|
|
|
{ our $VERSION = '0.002' } |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
124
|
|
7
|
2
|
|
|
2
|
|
11
|
use JSON::PP qw< decode_json >; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
96
|
|
8
|
2
|
|
|
2
|
|
12
|
use Scalar::Util qw< blessed >; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
70
|
|
9
|
2
|
|
|
2
|
|
16
|
use PDF::Collage::Template (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
47
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
10
|
use Moo; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
12
|
2
|
|
|
2
|
|
751
|
use experimental qw< signatures >; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
12
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
283
|
use namespace::clean; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
23
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has resolver => (is => ro => required => 1 => coerce => \&__resolver); |
17
|
|
|
|
|
|
|
has _selectors => (is => 'lazy'); |
18
|
|
|
|
|
|
|
|
19
|
6
|
|
|
6
|
|
58
|
sub _build__selectors ($self) { |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
10
|
|
20
|
|
|
|
|
|
|
my @selectors = |
21
|
9
|
|
|
|
|
42
|
map { s{\.json}{}rmxs } |
22
|
6
|
|
|
|
|
48
|
grep { m{\.json \z}mxs } |
|
12
|
|
|
|
|
59652
|
|
23
|
|
|
|
|
|
|
$self->resolver->get_sub_resolver('definitions')->list_asset_keys; |
24
|
6
|
|
|
|
|
145
|
return \@selectors; |
25
|
|
|
|
|
|
|
} ## end sub _build__selectors |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
1
|
0
|
sub contains ($self, $sel) { defined($self->_selector_from($sel)) } |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
28
|
|
|
|
|
|
|
|
29
|
21
|
|
|
21
|
1
|
5023
|
sub get ($self, $selector) { |
|
21
|
|
|
|
|
40
|
|
|
21
|
|
|
|
|
63
|
|
|
21
|
|
|
|
|
36
|
|
30
|
21
|
100
|
|
|
|
121
|
$selector = $self->_selector_from($selector) |
31
|
|
|
|
|
|
|
or croak 'invalid selector'; |
32
|
|
|
|
|
|
|
|
33
|
19
|
|
|
|
|
75
|
my $resolver = $self->resolver; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# my $def = $resolver->get_sub_resolver('definitions') |
36
|
|
|
|
|
|
|
# ->get_asset("$selector.json")->parsed_as_json; |
37
|
19
|
|
|
|
|
123
|
my $def = $resolver->get_asset("./definitions/$selector.json")->parsed_as_json; |
38
|
|
|
|
|
|
|
|
39
|
19
|
50
|
|
|
|
109814
|
$def = { commands => $def } unless ref($def) eq 'HASH'; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$def->{functions} = { |
42
|
0
|
|
|
0
|
|
0
|
as_data => sub ($key) { $resolver->get_asset($key)->raw_data }, |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
43
|
49
|
|
|
49
|
|
61
|
as_file => sub ($key) { $resolver->get_asset($key)->file }, |
|
49
|
|
|
|
|
309
|
|
|
49
|
|
|
|
|
58228
|
|
|
49
|
|
|
|
|
104
|
|
44
|
19
|
|
|
|
|
196
|
}; |
45
|
|
|
|
|
|
|
|
46
|
19
|
|
|
|
|
520
|
return PDF::Collage::Template->new($def); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
12
|
|
|
12
|
1
|
10810
|
sub render ($self, $selector = undef, $data = undef) { |
|
12
|
|
|
|
|
30
|
|
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
20
|
|
|
12
|
|
|
|
|
25
|
|
50
|
12
|
100
|
|
|
|
49
|
($selector, $data) = ($data, $selector) if ref($selector); |
51
|
12
|
|
|
|
|
49
|
return $self->get($selector)->render($data); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# coercion function to get a Data::Resolver CDDE reference back |
55
|
6
|
|
|
6
|
|
1576
|
sub __resolver ($candidate) { |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
16
|
|
56
|
6
|
100
|
|
|
|
37
|
return $candidate if blessed($candidate); |
57
|
5
|
|
|
|
|
14
|
my $class = $candidate->{class}; |
58
|
5
|
|
|
|
|
31
|
my $path = "$class.pm" =~ s{::}{/}rgmxs; |
59
|
5
|
|
|
|
|
33
|
require $path; |
60
|
5
|
|
|
|
|
104
|
return $class->new($candidate->%*); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
21
|
|
|
21
|
|
42
|
sub _selector_from ($self, $selector) { |
|
21
|
|
|
|
|
51
|
|
|
21
|
|
|
|
|
66
|
|
|
21
|
|
|
|
|
26
|
|
64
|
21
|
|
|
|
|
464
|
my $sels = $self->_selectors; |
65
|
21
|
100
|
66
|
|
|
244
|
$selector //= $sels->[0] if $sels->@* == 1; |
66
|
21
|
100
|
|
|
|
82
|
return undef unless defined $selector; |
67
|
20
|
|
|
|
|
64
|
my @candidates = grep { $selector eq $_ } $sels->@*; |
|
32
|
|
|
|
|
90
|
|
68
|
20
|
100
|
|
|
|
120
|
return @candidates ? $candidates[0] : undef; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
6
|
|
|
6
|
1
|
5627
|
sub selectors ($self) { $self->_selectors->@* } |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
129
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
1; |