Moose/Role/HasTimeReport.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 2 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 96.3% 53 / 55 CC 3 SCAR 3.6
CC
3
Cov
98%
_build_time
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.4
« Moose/Load.pm ↑ Summary Moose/Report/Method.pm »
1 package Test::Class::Moose::Role::HasTimeReport;
2  
3 # ABSTRACT: Report timing role
4  
5 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 ▶use 5.010000;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 30 our $VERSION = '1.00';
12  
13 30 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 30 ▶use Benchmark qw(timediff timestr :hireswallclock);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 30 ▶use Test::Class::Moose::Report::Time;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 has '_start_benchmark' => (
18 is => 'ro',
19 isa => 'Benchmark',
20 lazy => 1,
21 534 ▶ default => sub { Benchmark->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 30 predicate => '_has_start_benchmark',
23 );
24  
25 has '_end_benchmark' => (
26 is => 'ro',
27 isa => 'Benchmark',
28 lazy => 1,
29 519 ▶ default => sub { Benchmark->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
30 30 predicate => '_has_end_benchmark',
31 );
32  
33 30 has 'time' => (
34 is => 'ro',
35 isa => 'Test::Class::Moose::Report::Time',
36 lazy => 1,
37 builder => '_build_time',
38 );
39  
40 # If Time::HiRes is available these will be non-integers
41 has 'start_time' => (
42 is => 'ro',
43 isa => 'Num',
44 lazy => 1,
45 212 ▶ default => sub { $_[0]->_start_benchmark->[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
46 30 );
47  
48 has 'end_time' => (
49 is => 'ro',
50 isa => 'Num',
51 lazy => 1,
52 212 ▶ default => sub { $_[0]->_end_benchmark->[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
53 30 );
54  
55 236 ▶sub _build_time {
Subroutine _build_time: called CC=3 SCAR=11.0
56 236 my $self = shift;
57  
58 # If we don't have start & end marked we'll return a report with zero time
59 # elapsed.
60 236 ▶ unless ( $self->_has_start_benchmark && $self->_has_end_benchmark ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_has_start_benchmark and $self->_has_end_benchmark) 3 233 236
Condition66%2/3
$self->_has_start_benchmark and $self->_has_end_benchmark
!ll&&!rl&&r
03233
MC/DC50%1/2
$self->_has_start_benchmark and $self->_has_end_benchmark
$self->_has_start_benchmark $self->_has_end_benchmark
Truth table66%2/3
A and B
A= $self->_has_start_benchmarkB= $self->_has_end_benchmark
ABresult
0X0
100
111
61 3 my $benchmark = Benchmark->new;
62 3 return Test::Class::Moose::Report::Time->new(
63 timediff => timediff( $benchmark, $benchmark ) );
64 }
65  
66 233 return Test::Class::Moose::Report::Time->new( timediff =>
67 timediff( $self->_end_benchmark, $self->_start_benchmark ) );
68 }
69  
70 30 1;
71  
72 __END__
« Moose/Load.pm ↑ Summary Moose/Report/Method.pm »