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   237 use strict;
  30         80  
  30         1369  
6 30     30   187 use warnings;
  30         64  
  30         2012  
7 30     30   201 use namespace::autoclean;
  30         67  
  30         311  
8              
9 30     30   2768 use 5.010000;
  30         125  
10              
11             our $VERSION = '1.00';
12              
13 30     30   194 use Moose;
  30         63  
  30         289  
14 30     30   221221 use Benchmark qw(timestr :hireswallclock);
  30         68  
  30         249  
15 30     30   4210 use List::Util qw( max );
  30         71  
  30         11705  
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 513 my $self = shift;
44 217         559 return { map { $_ => $self->$_ } qw( real user system ) };
  651         31243  
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 1.00
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/Test-More/test-class-moose/issues>.
107              
108             =head1 SOURCE
109              
110             The source code repository for Test-Class-Moose can be found at L<https://github.com/Test-More/test-class-moose>.
111              
112             =head1 AUTHORS
113              
114             =over 4
115              
116             =item *
117              
118             Curtis "Ovid" Poe <ovid@cpan.org>
119              
120             =item *
121              
122             Dave Rolsky <autarch@urth.org>
123              
124             =item *
125              
126             Chad Granum <exodist@cpan.org>
127              
128             =back
129              
130             =head1 COPYRIGHT AND LICENSE
131              
132             This software is copyright (c) 2012 - 2025 by Curtis "Ovid" Poe.
133              
134             This is free software; you can redistribute it and/or modify it under
135             the same terms as the Perl 5 programming language system itself.
136              
137             The full text of the license can be found in the
138             F<LICENSE> file included with this distribution.
139              
140             =cut