Tapper/Reports/DPath/Mason.pm

filter: Statementstmt 76.8% 53 / 69 Branchbran 36.3% 8 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 71.1% 74 / 104 CC 12 SCAR 17.9
CC
12
Cov
67%
render_file
11.5
render_template
8.1
render
3.0
CRAP 6.0
« Tapper/Reports/DPath.pm ↑ Summary Tapper/Reports/DPath/TT.pm »
1 ## no critic (RequireUseStrict)
2 package Tapper::Reports::DPath::Mason;
3 4 our $AUTHORITY = 'cpan:TAPPER';
4 # ABSTRACT: Mix DPath into Mason templates
5 4 $Tapper::Reports::DPath::Mason::VERSION = '5.0.5';
6 4 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶ use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶ use HTML::Mason;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶ use Cwd 'cwd';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶ use File::ShareDir 'module_dir';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶ use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 Moose::Exporter->setup_import_methods(as_is => [ 'render' ] );
15  
16 4 has debug => ( is => 'rw');
17 4 has puresqlabstract => ( is => 'rw', default => 0);
18  
19 5 ▶ sub render {
Subroutine render: called CC=3 SCAR=11.0
Pod documented
20 5 my ($self, %args) = @_;
21  
22 5 my $file = $args{file};
23 5 my $template = $args{template};
24  
25 5 ▶ return $self->render_file ($file) if $file;
Branch: 1 branch
BranchTrueFalseTotal
if $file 1 4 5
26 4 ▶ return $self->render_template ($template) if $template;
Branch: 1 branch
BranchTrueFalseTotal
if $template 4 0 4
27 }
28  
29 4 ▶ sub render_template {
Subroutine render_template: called CC=5 SCAR=20.9
Pod documented
30 4 my ($self, $template) = @_;
31  
32 4 my $outbuf;
33 4 my $comp_root = module_dir('Tapper::Reports::DPath::Mason');
34  
35 4 local $Tapper::Reports::DPath::puresqlabstract = $self->puresqlabstract;
36 4 my $interp = new HTML::Mason::Interp
37 (
38 use_object_files => 1,
39 comp_root => $comp_root,
40 out_method => \$outbuf,
41 preloads => [ '/mason_include.pl' ],
42 );
43 4 my $anon_comp = eval {
44 4 $interp->make_component
45 (
46 comp_source => $template,
47 name => '/virtual/tapper_reports_dpath_mason',
48 );
49 };
50 4 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
51 0 my $msg = "Tapper::Reports::DPath::Mason::render_template::make_component: ".$@;
52 0 print STDERR $msg;
53 0 ▶ return $msg if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
54 0 return '';
55 }
56 4 eval {
57 4 $interp->exec($anon_comp);
58 };
59 4 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 4 4
60 0 my $msg = "Tapper::Reports::DPath::Mason::render_template::exec(anon_comp): ".$@;
61 0 print STDERR $msg;
62 0 ▶ return $msg if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
63 0 return '';
64 }
65 4 return $outbuf;
66 }
67  
68 1 ▶ sub render_file {
Subroutine render_file: called CC=6 SCAR=24.5
Pod documented
69 1 my ($self, $file) = @_;
70  
71 # must be absolute to mason, although meant relative in real world
72 1 ▶ $file = "/$file" unless $file =~ m(^/);
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ m[^/] 0 1 1
73  
74 1 my $outbuf;
75 my $interp;
76 1 eval {
77 1 $interp = new HTML::Mason::Interp(
78 use_object_files => 1,
79 comp_root => cwd(),
80 out_method => \$outbuf,
81 );
82 };
83 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
84 0 my $msg = "Tapper::Reports::DPath::Mason::render_file::new_Interp: ".$@;
85 0 print STDERR $msg;
86 0 ▶ return $msg if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
87 0 return '';
88 }
89 1 eval { $interp->exec($file) };
90 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
91 0 my $msg = "Tapper::Reports::DPath::Mason::render_file::exec(file): ".$@;
92 0 print STDERR $msg;
93 0 ▶ return $msg if $self->debug;
Branch: 1 branch
BranchTrueFalseTotal
if $self->debug 0 0 0
94 0 return '';
95 }
96 1 return $outbuf;
97 }
98  
99 4 1;
100  
101 __END__
« Tapper/Reports/DPath.pm ↑ Summary Tapper/Reports/DPath/TT.pm »