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 29     29   498 use 5.010000;
  29         92  
6              
7             our $VERSION = '0.97';
8              
9 29     29   177 use Moose;
  29         68  
  29         218  
10 29     29   162839 use Benchmark qw(timestr :hireswallclock);
  29         58  
  29         180  
11 29     29   2671 use List::Util qw( max );
  29         61  
  29         1812  
12 29     29   185 use namespace::autoclean;
  29         65  
  29         206  
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 329 my $self = shift;
41 217         346 return { map { $_ => $self->$_ } qw( real user system ) };
  651         16375  
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.97
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