File Coverage

blib/lib/Test/Class/Moose/Report/Time.pm
Criterion Covered Total %
statement 17 19 89.4
branch n/a
condition n/a
subroutine 6 7 85.7
pod 2 2 100.0
total 25 28 89.2


line stmt bran cond sub pod time code
1             package Test::Class::Moose::Report::Time;
2              
3             # ABSTRACT: Reporting object for timing
4              
5 30     30   480 use 5.010000;
  30         110  
6              
7             our $VERSION = '0.98';
8              
9 30     30   185 use Moose;
  30         76  
  30         202  
10 30     30   164123 use Benchmark qw(timestr :hireswallclock);
  30         63  
  30         155  
11 30     30   2643 use List::Util qw( max );
  30         63  
  30         1710  
12 30     30   186 use namespace::autoclean;
  30         56  
  30         179  
13              
14             {
15             my @fields = qw( real user system );
16             for my $i ( 0 .. $#fields ) {
17             has $fields[$i] => (
18             is => 'ro',
19             isa => 'Num',
20             lazy => 1,
21             default => sub { max( $_[0]->_timediff->[$i], 0 ) },
22             init_arg => undef,
23             );
24             }
25             }
26              
27             has '_timediff' => (
28             is => 'ro',
29             isa => 'Benchmark',
30             required => 1,
31             init_arg => 'timediff',
32             );
33              
34             sub duration {
35 0     0 1 0 my $self = shift;
36 0         0 return timestr( $self->_timediff );
37             }
38              
39             sub as_hashref {
40 217     217 1 377 my $self = shift;
41 217         376 return { map { $_ => $self->$_ } qw( real user system ) };
  651         20241  
42             }
43              
44             __PACKAGE__->meta->make_immutable;
45              
46             1;
47              
48             __END__
49              
50             =pod
51              
52             =encoding UTF-8
53              
54             =head1 NAME
55              
56             Test::Class::Moose::Report::Time - Reporting object for timing
57              
58             =head1 VERSION
59              
60             version 0.98
61              
62             =head1 DESCRIPTION
63              
64             Note that everything in here is experimental and subject to change.
65              
66             All times are in seconds.
67              
68             =head1 ATTRIBUTES
69              
70             =head2 C<real>
71              
72             my $real = $time->real;
73              
74             Returns the "real" amount of time the class or method took to run.
75              
76             =head2 C<user>
77              
78             my $user = $time->user;
79              
80             Returns the "user" amount of time the class or method took to run.
81              
82             =head2 C<system>
83              
84             my $system = $time->system;
85              
86             Returns the "system" amount of time the class or method took to run.
87              
88             =head1 METHODS
89              
90             =head2 C<duration>
91              
92             Returns the returns a human-readable representation of the time this class or
93             method took to run. Something like:
94              
95             0.00177908 wallclock secs ( 0.00 usr + 0.00 sys = 0.00 CPU)
96              
97             =head2 C<as_hashref>
98              
99             Returns the C<real>, C<user>, and C<system> time values in a hashref.
100              
101             =head1 SUPPORT
102              
103             Bugs may be submitted at L<https://github.com/houseabsolute/test-class-moose/issues>.
104              
105             I am also usually active on IRC as 'autarch' on C<irc://irc.perl.org>.
106              
107             =head1 SOURCE
108              
109             The source code repository for Test-Class-Moose can be found at L<https://github.com/houseabsolute/test-class-moose>.
110              
111             =head1 AUTHORS
112              
113             =over 4
114              
115             =item *
116              
117             Curtis "Ovid" Poe <ovid@cpan.org>
118              
119             =item *
120              
121             Dave Rolsky <autarch@urth.org>
122              
123             =back
124              
125             =head1 COPYRIGHT AND LICENSE
126              
127             This software is copyright (c) 2012 - 2019 by Curtis "Ovid" Poe.
128              
129             This is free software; you can redistribute it and/or modify it under
130             the same terms as the Perl 5 programming language system itself.
131              
132             The full text of the license can be found in the
133             F<LICENSE> file included with this distribution.
134              
135             =cut