File Coverage

blib/lib/Devel/Trace/Subs/Text.pm
Criterion Covered Total %
statement 37 37 100.0
branch 15 20 75.0
condition 5 6 83.3
subroutine 8 8 100.0
pod 1 1 100.0
total 66 72 91.6


line stmt bran cond sub pod time code
1             package Devel::Trace::Subs::Text;
2 6     6   39479 use 5.008;
  6         19  
3 6     6   30 use strict;
  6         11  
  6         127  
4 6     6   30 use warnings;
  6         10  
  6         171  
5              
6 6     6   27 use Data::Dumper;
  6         8  
  6         282  
7 6     6   32 use Exporter;
  6         19  
  6         203  
8 6     6   16943 use Template;
  6         137594  
  6         2433  
9              
10             our $VERSION = '0.21';
11             our @ISA = qw(Exporter);
12             our @EXPORT_OK = qw(text);
13              
14             my ($stack_tpl, $flow_tpl, $all_tpl);
15              
16             sub text {
17              
18 13     13 1 65810 my %p = @_;
19              
20 13         31 my $file = $p{file};
21 13         24 my $want = $p{want};
22 13         22 my $data = $p{data};
23              
24 13 100 100     99 if ($want && $want eq 'stack') {
    100 66        
25              
26 4         35 my $template = Template->new;
27              
28 4 100       26414 if ($file) {
29              
30 3 50       20 $template->process(
31             \$stack_tpl,
32             {stack => $data},
33             $file
34             ) || die $template->error;
35             }
36             else {
37 1 50       5 $template->process(
38             \$stack_tpl,
39             {stack => $data},
40             ) || die $template->error;
41             }
42             }
43             elsif ($want && $want eq 'flow') {
44              
45 4         28 my $template = Template->new;
46              
47 4 100       1612 if ($file) {
48              
49 3 50       17 $template->process(
50             \$flow_tpl,
51             {flow => $data},
52             $file
53             ) || die $template->error;
54             }
55             else {
56 1 50       5 $template->process(
57             \$flow_tpl,
58             {flow => $data}
59             ) || die $template->error;
60             }
61             }
62             else {
63 5         43 my $template = Template->new;
64              
65 5 100       72626 if ($file) {
66              
67 4 50       20 $template->process(
68             \$all_tpl,
69             $data,
70             $file,
71             ) || die $template->error;
72             }
73             else {
74             $template->process(\$all_tpl, {
75             flow => $data->{flow},
76             stack => $data->{stack},
77 1         7 });
78             }
79             }
80             }
81              
82             BEGIN {
83              
84 6     6   20 $flow_tpl = <
85              
86             Code flow:
87              
88             [% FOREACH entry IN flow -%]
89             [% entry.name %]: [% entry.value %]
90             [% END %]
91             EOF
92              
93 6         14 $stack_tpl = <
94              
95             Stack trace:
96              
97             [%- FOREACH entry IN stack %]
98             in: [% entry.in %]
99             sub: [% entry.sub %]
100             file: [% entry.filename %]
101             line: [% entry.line %]
102             package: [% entry.package %]
103             [% END %]
104             EOF
105              
106 6         142 $all_tpl = <
107              
108             Code flow:
109              
110             [% FOREACH entry IN flow -%]
111             [% entry.name %]: [% entry.value %]
112             [% END %]
113             Stack trace:
114              
115             [%- FOREACH entry IN stack %]
116             in: [% entry.in %]
117             sub: [% entry.sub %]
118             file: [% entry.filename %]
119             line: [% entry.line %]
120             package: [% entry.package %]
121             [% END %]
122             EOF
123             }
124             __END__