blib/lib/Template/Plugin/DataPrinter.pm

filter: Statementstmt 100% 42 / 42 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 100% 57 / 57 SCAR 6.9
CC
2
Cov
100%
_css
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
↑ Summary
1 package Template::Plugin::DataPrinter;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use base 'Template::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Template Toolkit dumper plugin using Data::Printer
7 3 our $VERSION = '0.016'; # VERSION
8  
9 3 ▶use HTML::FromANSI::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Hash::Merge::Simple qw< merge >;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use version 0.77;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 sub new {
14 8 ▶ my ($class, $context, $params) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
15  
16 8 require Data::Printer;
17 8 Data::Printer->VERSION(1.0.0);
18 my $dp_params = merge( {
19 colored => 1,
20 return_value => 'dump',
21 use_prototypes => 0,
22 },
23 8 $params->{dp});
24 8 Data::Printer->import(%$dp_params);
25  
26 my $hfat_params = merge( {
27 class_prefix => 'ansi_',
28 no_plain_tags => 1,
29 },
30 8 $params->{hfat});
31  
32 8 my $hfat = HTML::FromANSI::Tiny->new(%$hfat_params);
33 8 my $self = bless {
34 _CONTEXT => $context,
35 hfat => $hfat,
36 }, $class;
37  
38 8 return $self;
39 }
40  
41 sub dump {
42 9 ▶ my $self = shift;
Subroutine dump: called CC=1 SCAR=0.0
Pod documented
43 9 my $text = join('', map { p($_) . "\n" } @_);
44 9 return $text;
45 }
46  
47 sub dump_html {
48 5 ▶ my $self = shift;
Subroutine dump_html: called CC=1 SCAR=0.0
Pod documented
49  
50 5 my $html = $self->_css;
51 5 my $text = $self->dump(@_);
52 5 $html .= "<pre>\n" . $self->{hfat}->html($text) . '</pre>';
53 5 return $html;
54 }
55  
56 sub _css {
57 # Short of a better plan, emit the css on-demand before the first dump_html
58 5 ▶ my $self = shift;
Subroutine _css: called CC=2 SCAR=6.9
59 5 ▶ return '' if $self->{done_css};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"done_css"} 1 4 5
60  
61 4 $self->{done_css} = 1;
62 4 return $self->{hfat}->style_tag . "\n";
63 }
64  
65 3 1;
66  
67 __END__
↑ Summary