File Coverage

blib/lib/Attribute/Profiled.pm
Criterion Covered Total %
statement 34 34 100.0
branch 2 2 100.0
condition n/a
subroutine 12 12 100.0
pod 0 1 0.0
total 48 49 97.9


line stmt bran cond sub pod time code
1             package Attribute::Profiled;
2              
3 1     1   30535 use 5.006;
  1         6  
  1         60  
4 1     1   10 use strict;
  1         2  
  1         47  
5 1     1   6 use warnings;
  1         8  
  1         93  
6              
7             our $VERSION = '0.03';
8              
9 1     1   2759 use Attribute::Handlers;
  1         7185  
  1         6  
10 1     1   1060 use Hook::LexWrap;
  1         4320  
  1         6  
11              
12             our $_Profiler;
13              
14             sub UNIVERSAL::Profiled : ATTR(CODE) {
15 3     3 0 2736 my($package, $symbol, $referent, $attr, $data, $phase) = @_;
16 3         6 my $meth = *{$symbol}{NAME};
  3         8  
17 1     1   82 no warnings 'redefine';
  1         2  
  1         168  
18              
19             wrap $symbol,
20             pre => sub {
21 13 100   13   2109 unless ($_Profiler) {
22 1         18 $_Profiler = Benchmark::Timer::ReportOnDestroy->new;
23             }
24 13         95 $_Profiler->start("$package\::$meth");
25             },
26             post => sub {
27 13     13   449 $_Profiler->stop("$package\::$meth");
28 3         29 };
29 1     1   6 }
  1         1  
  1         6  
30              
31             package Benchmark::Timer::ReportOnDestroy;
32 1     1   378 use base qw(Benchmark::Timer);
  1         2  
  1         1087  
33              
34             sub DESTROY {
35 1     1   544 my $self = shift;
36 1         12 $self->report;
37             }
38              
39              
40             1;
41             __END__