Tapper/Reports/DPath/TT.pm

filter: Statementstmt 90.8% 89 / 98 Branchbran 50.0% 7 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.8% 26 / 28 Podpod 100% 5 / 5 totaltotal 87.5% 127 / 145 CC 8 SCAR 5.8
CC
8
Cov
86%
testrundb_hostnames
6.0
render_template
3.3
render
3.0
CRAP 1.8
« Tapper/Reports/DPath/Mason.pm ↑ Summary auto/Tapper/Reports/DPath/Mason/mason_include.pl »
1 ## no critic (RequireUseStrict)
2 package Tapper::Reports::DPath::TT;
3 6 our $AUTHORITY = 'cpan:TAPPER';
4 # ABSTRACT: Mix DPath into Template-Toolkit templates
5 6 $Tapper::Reports::DPath::TT::VERSION = '5.0.5';
6 6 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶ use Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶ use Cwd 'cwd';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 6 ▶ use Template::Stash;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # modules needed inside the TT template for vmethods
15 6 ▶ use Tapper::Reports::DPath 'reportdata', 'testrundata', 'testplandata';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶ use Tapper::Model 'model';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ use Data::DPath 'dpath';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶ use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶ use YAML::XS;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶ use Data::Structure::Util 'unbless';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶ use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 Moose::Exporter->setup_import_methods(as_is => [ 'render' ] );
25  
26 6 has debug => ( is => 'rw');
27 6 has puresqlabstract => ( is => 'rw', default => 0);
28 6 has include_path => ( is => 'rw', default => "");
29 6 has substitutes => ( is => 'rw', default => undef);
30 6 has eval_perl => ( is => 'rw', default => 0);
31  
32 sub get_template
33 12 ▶ {
Subroutine get_template: called CC=2 SCAR=6.9
Pod documented
34 12 my ($self) = @_;
35  
36 12 ▶ my $tt = Template->new({EVAL_PERL => $self->eval_perl,
Branch: 1 branch
BranchTrueFalseTotal
$self->include_path ? : 0 12 12
37 $self->include_path ? (INCLUDE_PATH => $self->include_path) : (),
38 });
39 12 ▶ $Template::Stash::SCALAR_OPS->{reportdata} = sub { reportdata($_[0]) };
Subroutine __ANON__: called CC=1 SCAR=0.0
40 12 ▶ $Template::Stash::SCALAR_OPS->{testrundata} = sub { testrundata($_[0]) };
Subroutine __ANON__: called CC=1 SCAR=0.0
41 12 ▶ $Template::Stash::SCALAR_OPS->{testrundata_nohost} = sub { testrundata($_[0], 1) }; # nohost=1
Subroutine __ANON__: called CC=1 SCAR=0.0
42 0 ▶ $Template::Stash::SCALAR_OPS->{testplandata} = sub { testplandata($_[0]) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
43 12 ▶ $Template::Stash::SCALAR_OPS->{dpath_match}= sub { my ($path, $data) = @_; dpath($path)->match($data); };
Subroutine __ANON__: called CC=1 SCAR=0.0
44 12 ▶ $Template::Stash::LIST_OPS->{to_json} = sub { JSON->new->pretty->encode(unbless $_[0]) };
Subroutine __ANON__: called CC=1 SCAR=0.0
45 12 ▶ $Template::Stash::LIST_OPS->{to_yaml} = sub { YAML::XS::Dump(unbless $_[0]) };
Subroutine __ANON__: called CC=1 SCAR=0.0
46 12 ▶ $Template::Stash::LIST_OPS->{Dumper} = sub { $Data::Dumper::Sortkeys = 1; Dumper @_ };
Subroutine __ANON__: called CC=1 SCAR=0.0
47 12 return $tt;
48 }
49  
50 0 ▶ sub testrundb_hostnames {
Subroutine testrundb_hostnames: not called CC=2 SCAR=17.9
Pod documented
51 0 my $host_iter = model('TestrunDB')->resultset("Host")->search({ });
52 0 my %hosts = ();
53 0 ▶ while (my $h = $host_iter->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $h = $host_iter->next) 0 0 0
54 0 $hosts{$h->name} = { id => $h->id,
55 name => $h->name,
56 free => $h->free,
57 active => $h->active,
58 comment => $h->comment,
59 is_deleted => $h->is_deleted,
60 };
61 }
62 0 return \%hosts;
63 }
64  
65 12 ▶ sub render {
Subroutine render: called CC=3 SCAR=11.0
Pod documented
66 12 my ($self, %args) = @_;
67  
68 12 my $file = $args{file};
69 12 my $template = $args{template};
70  
71 12 ▶ return $self->render_file ($file) if $file;
Branch: 1 branch
BranchTrueFalseTotal
if $file 1 11 12
72 11 ▶ return $self->render_template ($template) if $template;
Branch: 1 branch
BranchTrueFalseTotal
if $template 11 0 11
73 }
74  
75 11 ▶ sub render_template {
Subroutine render_template: called CC=3 SCAR=12.0
Pod documented
76 11 my ($self, $template) = @_;
77  
78 11 my $outbuf;
79 11 my $tt = $self->get_template();
80  
81 11 local $Tapper::Reports::DPath::puresqlabstract = $self->puresqlabstract;
82 11 ▶ if(not $tt->process(\$template, {reportdata => \&reportdata,
Branch: 2 branches
BranchTrueFalseTotal
unless ($tt->process(\$template, {"reportdata", \&Tapper::Reports::DPath::TT::reportdata, "testrundata", \&Tapper::Reports::DPath::TT::testrundata, "testplandata", \&Tapper::Reports::DPath::TT::testplandata, "testrundb_hostnames", \&Tapper::Reports::DPath::TT::testrundb_hostnames, defined $self->substitutes ? %{$self->substitutes;} : ()}, \$outbuf)) 0 11 11
defined $self->substitutes ? : 0 11 11
83 testrundata => \&testrundata,
84 testplandata => \&testplandata,
85 testrundb_hostnames => \&testrundb_hostnames,
86 0 defined $self->substitutes ? ( %{$self->substitutes} ) : (),
87 }, \$outbuf)) {
88 0 die $tt->error;
89 }
90 11 return $outbuf;
91 }
92  
93 1 ▶ sub render_file {
Subroutine render_file: called CC=2 SCAR=7.2
Pod documented
94 1 my ($self, $file) = @_;
95  
96 1 my $outbuf;
97 1 my $tt = $self->get_template();
98  
99 1 ▶ if(not $tt->process($file, {}, \$outbuf)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tt->process($file, {}, \$outbuf)) 0 1 1
100 0 die Template->error();
101 }
102 1 return $outbuf;
103 }
104  
105  
106 6 1;
107  
108 __END__
« Tapper/Reports/DPath/Mason.pm ↑ Summary auto/Tapper/Reports/DPath/Mason/mason_include.pl »