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 4     4   72025 use 5.008;
  4         21  
3 4     4   19 use strict;
  4         5  
  4         74  
4 4     4   23 use warnings;
  4         7  
  4         102  
5              
6 4     4   26 use Data::Dumper;
  4         6  
  4         198  
7 4     4   24 use Exporter;
  4         4  
  4         112  
8 4     4   2676 use Template;
  4         71761  
  4         1097  
9              
10             our $VERSION = '0.23';
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 62148 my %p = @_;
19              
20 13         28 my $file = $p{file};
21 13         24 my $want = $p{want};
22 13         21 my $data = $p{data};
23              
24 13 100 100     75 if ($want && $want eq 'stack') {
    100 66        
25              
26 4         34 my $template = Template->new;
27              
28 4 100       22329 if ($file) {
29              
30 3 50       17 $template->process(
31             \$stack_tpl,
32             {stack => $data},
33             $file
34             ) || die $template->error;
35             }
36             else {
37 1 50       6 $template->process(
38             \$stack_tpl,
39             {stack => $data},
40             ) || die $template->error;
41             }
42             }
43             elsif ($want && $want eq 'flow') {
44              
45 4         32 my $template = Template->new;
46              
47 4 100       1644 if ($file) {
48              
49 3 50       13 $template->process(
50             \$flow_tpl,
51             {flow => $data},
52             $file
53             ) || die $template->error;
54             }
55             else {
56 1 50       4 $template->process(
57             \$flow_tpl,
58             {flow => $data}
59             ) || die $template->error;
60             }
61             }
62             else {
63 5         34 my $template = Template->new;
64              
65 5 100       29768 if ($file) {
66              
67 4 50       15 $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 4     4   16 $flow_tpl = <
85              
86             Code flow:
87              
88             [% FOREACH entry IN flow -%]
89             [% entry.name %]: [% entry.value %]
90             [% END %]
91             EOF
92              
93 4         5 $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 4         115 $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__