File Coverage

blib/lib/Devel/Profiler/Plugins/Template.pm
Criterion Covered Total %
statement 21 42 50.0
branch 0 4 0.0
condition 1 2 50.0
subroutine 7 9 77.7
pod n/a
total 29 57 50.8


line stmt bran cond sub pod time code
1             package Devel::Profiler::Plugins::Template;
2              
3 1     1   1002 use 5.006_001;
  1         4  
  1         43  
4              
5 1     1   724 use Devel::Profiler::Plugins::Template::Context;
  1         4  
  1         34  
6              
7 1     1   7 use strict;
  1         2  
  1         35  
8 1     1   6 use warnings FATAL => qw(all);
  1         2  
  1         61  
9              
10             #---------------------------------------------------------------------
11             # constants and global variables
12             #---------------------------------------------------------------------
13             our $VERSION = 0.01;
14              
15 1   50 1   5 use constant DEBUG => $ENV{DEVEL_PROFILER_PLUGIN_DEBUG} || 0;
  1         2  
  1         259  
16              
17              
18             #---------------------------------------------------------------------
19             # make sure that a named subroutine consists of only characters
20             # perl likes in subroutines.
21             # stolen directly from ModPerl::RegistryCooker
22             #---------------------------------------------------------------------
23             sub _tidy_sub {
24              
25 0     0     my $name = shift;
26              
27             # translate the name into a suitable name for a perl subroutine
28             # stolen directly from ModPerl::RegistryCooker
29 0           $name =~ s/([^A-Za-z0-9_])/sprintf("_%2x", unpack("C", $1))/eg;
  0            
30 0           $name =~ s/^(\d)/_$1/;
31              
32 0           print STDERR __PACKAGE__ . join ' ', "::_tidy_sub() returned",
33             "$name\n"
34             if DEBUG;
35              
36 0           return $name;
37             }
38              
39              
40             #---------------------------------------------------------------------
41             # call Devel::Profiler::instrument()
42             #---------------------------------------------------------------------
43             sub _instrument {
44              
45 0     0     my $package = shift;
46 0           my $sub = shift;
47 0           my $name = shift;
48              
49 0           our $cv = shift;
50              
51             # don't re-instrument the block - it throws off our counts
52             {
53 1     1   5 no strict;
  1         3  
  1         122  
  0            
54 0 0         return if defined *{$sub}{CODE};
  0            
55             }
56              
57             # stick the BLOCK in its own package so Devel::Profiler has
58             # something to wrap
59              
60 0           my $eval = <<"EOF";
61             package $package;
62             sub $name { shift; \$cv->(\@_) };
63             1;
64             EOF
65              
66 0           print STDERR __PACKAGE__ . join ' ', "::_instrument() eval'ing",
67             "$eval\n"
68             if DEBUG;
69              
70 0           eval $eval;
71              
72 0 0         die $@ if $@;
73              
74             # finally, call instrument()
75             {
76 1     1   5 no strict;
  1         2  
  1         138  
  0            
77 0           Devel::Profiler::instrument("${package}::", $name, *{$sub}{CODE});
  0            
78             }
79              
80 0           print STDERR __PACKAGE__ . join ' ', "::_instrument() instrumented",
81             "${package}::${name}\n"
82             if DEBUG;
83             }
84              
85             1;
86              
87              
88             __END__