Bench/Report/Text.pm

filter: Statementstmt 100% 14 / 14 Branchbran 100% 2 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod 100% 1 / 1 totaltotal 100% 20 / 20 CC 2 SCAR 4.1
CC
2
Cov
100%
report
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.5
« Bench.pm ↑ Summary Bench/Item.pm »
1 package Tool::Bench::Report::Text;
2 {
3 1 $Tool::Bench::Report::Text::VERSION = '0.003';
4 }
5 1 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use List::Util qw{min max sum };
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # ABSTRACT: How to build the Text Report
9  
10 =head1 SYNOPSIS
11  
12 At the very end of everything, you will likely want a nice clean report of
13 everything.
14  
15 my $bench = Tool::Bench->new;
16 $bench->add_items( true => sub{1},
17 die => sub{die},
18 ls => {code => sub{qx{ls}},
19 note => 'some note',
20 },
21 sleep => sub{sleep(1)},
22 );
23 $bench->run(4);
24 print $bench->report(format => 'Text');
25  
26 min max total avg count name
27 0.000 0.000 0.000 0.000 4 true
28 0.000 0.000 0.000 0.000 4 die
29 0.002 0.002 0.009 0.002 4 ls [some note]
30 1.000 1.000 4.000 1.000 4 sleep
31  
32 =head1 METHODS
33  
34 =head2 report
35  
36 This is the method that $bench->report will call to build the actual report.
37 The most important thing that is passed along by $bench is the item objects.
38  
39 $bench->report(format => 'Text');
40  
41 Will end up calling 'report' looking like:
42  
43 Tool::Bench::Report::Text->new->report(items => [...]);
44  
45 Common practice is that you return the report, rather then printing. This
46 allows the user to decide what they want to do with that report on there end.
47  
48 =cut
49  
50 1 ▶sub report {
Subroutine report: called CC=2 SCAR=6.9
Pod documented
51 1 my ($self,%args) = @_;
52  
53 sprintf qq{%s\n\n},
54 join qq{\n},
55 q{ min max total avg count name},
56 4 ▶ map{ sprintf q{%0.3f %0.3f %0.3f %0.3f % 5d %s %s},
Branch: 1 branch
BranchTrueFalseTotal
length $_->note ? : 1 3 4
57 $_->min_time,
58 $_->max_time,
59 $_->total_time,
60 $_->avg_time,
61 $_->total_runs,
62 $_->name,
63 #length($_->note) ? sprintf q{[NOTE: %s]}, $_->note : ''
64 length($_->note) ? sprintf q{[%s]}, $_->note : ''
65 1 } sort {$a->total_time <=> $b->total_time} @{$args{items}};
66
67 };
68  
69 1 1;
70  
« Bench.pm ↑ Summary Bench/Item.pm »