line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
## no critic (RequireUseStrict) |
2
|
|
|
|
|
|
|
package Tapper::Reports::DPath::TT; |
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TAPPER'; |
4
|
|
|
|
|
|
|
# ABSTRACT: Mix DPath into Template-Toolkit templates |
5
|
|
|
|
|
|
|
$Tapper::Reports::DPath::TT::VERSION = '5.0.2'; |
6
|
4
|
|
|
4
|
|
107093
|
use 5.010; |
|
4
|
|
|
|
|
11
|
|
7
|
4
|
|
|
4
|
|
828
|
use Moose; |
|
4
|
|
|
|
|
592979
|
|
|
4
|
|
|
|
|
29
|
|
8
|
4
|
|
|
4
|
|
21257
|
use Template; |
|
4
|
|
|
|
|
56930
|
|
|
4
|
|
|
|
|
119
|
|
9
|
4
|
|
|
4
|
|
25
|
use Cwd 'cwd'; |
|
4
|
|
|
|
|
6
|
|
|
4
|
|
|
|
|
175
|
|
10
|
4
|
|
|
4
|
|
1083
|
use Data::Dumper; |
|
4
|
|
|
|
|
8941
|
|
|
4
|
|
|
|
|
175
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
1741
|
use Template::Stash; |
|
4
|
|
|
|
|
38519
|
|
|
4
|
|
|
|
|
120
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# modules needed inside the TT template for vmethods |
15
|
4
|
|
|
4
|
|
822
|
use Tapper::Reports::DPath 'reportdata'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
39
|
|
16
|
4
|
|
|
4
|
|
863
|
use Tapper::Model 'model'; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
190
|
|
17
|
4
|
|
|
4
|
|
16
|
use Data::Dumper; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
150
|
|
18
|
4
|
|
|
4
|
|
2058
|
use Data::DPath 'dpath'; |
|
4
|
|
|
|
|
3386
|
|
|
4
|
|
|
|
|
19
|
|
19
|
4
|
|
|
4
|
|
559
|
use DateTime; |
|
4
|
|
|
|
|
5
|
|
|
4
|
|
|
|
|
79
|
|
20
|
4
|
|
|
4
|
|
1769
|
use JSON; |
|
4
|
|
|
|
|
20186
|
|
|
4
|
|
|
|
|
27
|
|
21
|
4
|
|
|
4
|
|
2050
|
use YAML::XS; |
|
4
|
|
|
|
|
7497
|
|
|
4
|
|
|
|
|
197
|
|
22
|
4
|
|
|
4
|
|
1680
|
use Data::Structure::Util 'unbless'; |
|
4
|
|
|
|
|
3965
|
|
|
4
|
|
|
|
|
2080
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has debug => ( is => 'rw'); |
25
|
|
|
|
|
|
|
has puresqlabstract => ( is => 'rw', default => 0); |
26
|
|
|
|
|
|
|
has include_path => ( is => 'rw', default => ""); |
27
|
|
|
|
|
|
|
has substitutes => ( is => 'rw', default => undef); |
28
|
|
|
|
|
|
|
has eval_perl => ( is => 'rw', default => 0); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub get_template |
31
|
|
|
|
|
|
|
{ |
32
|
9
|
|
|
9
|
1
|
14
|
my ($self) = @_; |
33
|
|
|
|
|
|
|
|
34
|
9
|
50
|
|
|
|
316
|
my $tt = Template->new({EVAL_PERL => $self->eval_perl, |
35
|
|
|
|
|
|
|
$self->include_path ? (INCLUDE_PATH => $self->include_path) : (), |
36
|
|
|
|
|
|
|
}); |
37
|
9
|
|
|
1
|
|
17304
|
$Template::Stash::SCALAR_OPS->{reportdata} = sub { reportdata($_[0]) }; |
|
1
|
|
|
|
|
2302
|
|
38
|
9
|
|
|
1
|
|
46
|
$Template::Stash::SCALAR_OPS->{dpath_match}= sub { my ($path, $data) = @_; dpath($path)->match($data); }; |
|
1
|
|
|
|
|
4160
|
|
|
1
|
|
|
|
|
4
|
|
39
|
9
|
|
|
1
|
|
43
|
$Template::Stash::LIST_OPS->{to_json} = sub { JSON->new->pretty->encode(unbless $_[0]) }; |
|
1
|
|
|
|
|
2265
|
|
40
|
9
|
|
|
1
|
|
34
|
$Template::Stash::LIST_OPS->{to_yaml} = sub { YAML::XS::Dump(unbless $_[0]) }; |
|
1
|
|
|
|
|
2333
|
|
41
|
9
|
|
|
1
|
|
34
|
$Template::Stash::LIST_OPS->{Dumper} = sub { Dumper @_ }; |
|
1
|
|
|
|
|
23784
|
|
42
|
9
|
|
|
|
|
36
|
return $tt; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub testrundb_hostnames { |
46
|
0
|
|
|
0
|
1
|
0
|
my $host_iter = model('TestrunDB')->resultset("Host")->search({ }); |
47
|
0
|
|
|
|
|
0
|
my %hosts = (); |
48
|
0
|
|
|
|
|
0
|
while (my $h = $host_iter->next) { |
49
|
0
|
|
|
|
|
0
|
$hosts{$h->name} = { id => $h->id, |
50
|
|
|
|
|
|
|
name => $h->name, |
51
|
|
|
|
|
|
|
free => $h->free, |
52
|
|
|
|
|
|
|
active => $h->active, |
53
|
|
|
|
|
|
|
comment => $h->comment, |
54
|
|
|
|
|
|
|
is_deleted => $h->is_deleted, |
55
|
|
|
|
|
|
|
}; |
56
|
|
|
|
|
|
|
} |
57
|
0
|
|
|
|
|
0
|
return \%hosts; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub render { |
61
|
9
|
|
|
9
|
1
|
1590376
|
my ($self, %args) = @_; |
62
|
|
|
|
|
|
|
|
63
|
9
|
|
|
|
|
15
|
my $file = $args{file}; |
64
|
9
|
|
|
|
|
15
|
my $template = $args{template}; |
65
|
|
|
|
|
|
|
|
66
|
9
|
100
|
|
|
|
27
|
return $self->render_file ($file) if $file; |
67
|
8
|
50
|
|
|
|
27
|
return $self->render_template ($template) if $template; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub render_template { |
71
|
8
|
|
|
8
|
1
|
11
|
my ($self, $template) = @_; |
72
|
|
|
|
|
|
|
|
73
|
8
|
|
|
|
|
9
|
my $outbuf; |
74
|
8
|
|
|
|
|
21
|
my $tt = $self->get_template(); |
75
|
|
|
|
|
|
|
|
76
|
8
|
|
|
|
|
282
|
local $Tapper::Reports::DPath::puresqlabstract = $self->puresqlabstract; |
77
|
8
|
50
|
|
|
|
234
|
if(not $tt->process(\$template, {reportdata => \&reportdata, |
|
|
50
|
|
|
|
|
|
78
|
|
|
|
|
|
|
testrundb_hostnames => \&testrundb_hostnames, |
79
|
0
|
|
|
|
|
0
|
defined $self->substitutes ? ( %{$self->substitutes} ) : (), |
80
|
|
|
|
|
|
|
}, \$outbuf)) { |
81
|
0
|
|
|
|
|
0
|
die $tt->error; |
82
|
|
|
|
|
|
|
} |
83
|
8
|
|
|
|
|
6616
|
return $outbuf; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub render_file { |
87
|
1
|
|
|
1
|
1
|
2
|
my ($self, $file) = @_; |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
|
|
2
|
my $outbuf; |
90
|
1
|
|
|
|
|
4
|
my $tt = $self->get_template(); |
91
|
|
|
|
|
|
|
|
92
|
1
|
50
|
|
|
|
6
|
if(not $tt->process($file, {}, \$outbuf)) { |
93
|
0
|
|
|
|
|
0
|
die Template->error(); |
94
|
|
|
|
|
|
|
} |
95
|
1
|
|
|
|
|
27701
|
return $outbuf; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=pod |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=encoding UTF-8 |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 NAME |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Tapper::Reports::DPath::TT - Mix DPath into Template-Toolkit templates |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 SYNOPSIS |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
use Tapper::Reports::DPath::Mason 'render'; |
114
|
|
|
|
|
|
|
$result = render file => $filename; |
115
|
|
|
|
|
|
|
$result = render template => $string; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 METHODS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 get_template |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Render template processor with complete Tapper prelude set. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 render |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Render file or template. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 render_file |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
Render file. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 render_template |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Render template. |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 testrundb_hostnames |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Provide list of hosts from Tapper TestrunDB to be accessible in |
138
|
|
|
|
|
|
|
templates. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 AUTHORS |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=over 4 |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
AMD OSRC Tapper Team <tapper@amd64.org> |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item * |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Tapper Team <tapper-ops@amazon.com> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=back |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
This software is Copyright (c) 2016 by Advanced Micro Devices, Inc.. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
This is free software, licensed under: |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
The (two-clause) FreeBSD License |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |