MtPolicyd/Profiler/Timer.pm

filter: Statementstmt 100% 48 / 48 Branchbran 83.3% 5 / 6 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 10 / 10 Podpod 0.0% 0 / 4 totaltotal 90.4% 66 / 73 CC 6 SCAR 7.9
CC
6
Cov
96%
to_string
4.0
__ANON__
3.0
BEGIN
1.0
CRAP 2.2
« MtPolicyd/Plugin/GeoIPLookup.pm ↑ Summary MtPolicyd/SessionCache/Base.pm »
1 package Mail::MtPolicyd::Profiler::Timer;
2  
3 8 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 our $VERSION = '2.01'; # VERSION
7 # ABSTRACT: a profiler for the mtpolicyd
8  
9 8 ▶use Time::HiRes 'gettimeofday', 'tv_interval';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 8 has 'name' => ( is => 'rw', isa => 'Str', required => 1 );
12  
13 has 'start_time' => ( is => 'rw', isa => 'ArrayRef',
14 11 ▶ default => sub { [gettimeofday()] },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 8 );
16  
17 has 'ticks' => ( is => 'ro', isa => 'ArrayRef', lazy => 1,
18 9 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
19 8 );
20  
21 8 has 'parent' => ( is => 'ro', isa => 'Maybe[Mail::MtPolicyd::Profiler::Timer]' );
22  
23 around BUILDARGS => sub {
24 11 ▶ my $orig = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
25 11 my $class = shift;
26  
27 11 ▶ if ( @_ == 1 && !ref $_[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 1 and not ref $_[0]) { } 1 10 11
Condition66%2/3
@_ == 1 and not ref $_[0]
!ll&&!rl&&r
1001
MC/DC50%1/2
@_ == 1 and not ref $_[0]
@_ == 1 not ref $_[0]
Truth table66%2/3
A and not(B)
A= @_ == 1B= not ref $_[0]
ABresult
0X0
100
111
28 1 return $class->$orig( name => $_[0] );
29 } else {
30 10 return $class->$orig(@_);
31 }
32 8 };
33  
34 sub tick {
35 19 ▶ my ( $self, $msg ) = @_;
Subroutine tick: called CC=1 SCAR=0.0
Pod undocumented
36 19 my $now = [gettimeofday()];
37 19 my $delay = tv_interval($self->start_time, $now);
38 19 push( @{$self->ticks}, [ $delay, $msg ] );
39 19 return;
40 }
41  
42 sub stop {
43 7 ▶ my $self = shift;
Subroutine stop: called CC=1 SCAR=0.0
Pod undocumented
44 7 $self->tick('timer stopped');
45 }
46  
47 sub new_child {
48 6 ▶ my $self = shift;
Subroutine new_child: called CC=1 SCAR=0.0
Pod undocumented
49 6 my $timer = __PACKAGE__->new(
50 parent => $self,
51 @_
52 );
53 6 $self->tick('started timer '.$timer->name);
54 6 push( @{$self->ticks}, $timer );
55 6 return( $timer );
56 }
57  
58 sub to_string {
59 4 ▶ my $self = shift;
Subroutine to_string: called CC=4 SCAR=13.9
Pod undocumented
60 4 my $str = '';
61 4 foreach my $tick ( @{$self->ticks} ) {
62 15 ▶ if( ref $tick eq 'ARRAY' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $tick eq 'ARRAY') { } 12 3 15
elsif (ref $tick eq 'Mail::MtPolicyd::Profiler::Timer') { } 3 0 3
63 12 $str .= sprintf("%0f %s\n", @$tick );
64 } elsif( ref $tick eq 'Mail::MtPolicyd::Profiler::Timer' ) {
65 3 my $substr = $tick->to_string;
66 3 $substr =~ s/^/ /msg;
67 3 $str .= $substr;
68 }
69 }
70 4 return( $str );
71 }
72  
73 8 __PACKAGE__->meta->make_immutable;
74  
75 8 1;
76  
77 __END__
78  
79 =pod
80  
81 =encoding UTF-8
82  
83 =head1 NAME
84  
85 Mail::MtPolicyd::Profiler::Timer - a profiler for the mtpolicyd
86  
87 =head1 VERSION
88  
89 version 2.01
90  
91 =head1 AUTHOR
92  
93 Markus Benning <ich@markusbenning.de>
94  
95 =head1 COPYRIGHT AND LICENSE
96  
97 This software is Copyright (c) 2014 by Markus Benning <ich@markusbenning.de>.
98  
99 This is free software, licensed under:
100  
101 The GNU General Public License, Version 2, June 1991
102  
103 =cut
« MtPolicyd/Plugin/GeoIPLookup.pm ↑ Summary MtPolicyd/SessionCache/Base.pm »