File Coverage

blib/lib/Test/Class/Moose/Report/Time.pm
Criterion Covered Total %
statement 23 25 92.0
branch n/a
condition n/a
subroutine 8 9 88.8
pod 2 2 100.0
total 33 36 91.6


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