| 1 | package Tool::Bench::Report::JSON; | ||
| 2 | { | ||
| 3 | 1 | $Tool::Bench::Report::JSON::VERSION = '0.003'; | |
| 4 | } | ||
| 5 | 1 | ▶ | use Mouse; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use JSON; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 1 | ▶ | use List::Util qw{min max sum }; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 1 | ▶ | use Data::Dumper; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | =head1 JSON | ||
| 11 | |||
| 12 | Builds a json report as follows (though it does not format this nicely): | ||
| 13 | |||
| 14 | =head2 report | ||
| 15 | |||
| 16 | [ | ||
| 17 | { | ||
| 18 | 'max_time' => '3.50475311279297e-05', | ||
| 19 | 'total_runs' => 4, | ||
| 20 | 'min_time' => '2.09808349609375e-05', | ||
| 21 | 'avg_time' => '2.55107879638672e-05', | ||
| 22 | 'name' => 'true', | ||
| 23 | 'total_time' => '0.000102043151855469', | ||
| 24 | 'times' => [ | ||
| 25 | '2.40802764892578e-05', | ||
| 26 | '2.09808349609375e-05', | ||
| 27 | '3.50475311279297e-05', | ||
| 28 | '2.19345092773438e-05' | ||
| 29 | ] | ||
| 30 | }, | ||
| 31 | ] | ||
| 32 | |||
| 33 | =cut | ||
| 34 | |||
| 35 | 1 | ▶ | sub report { |
|
Subroutine
report: called CC=1 SCAR=0.0
Pod
documented
| |||
| 36 | 1 | my ($self,%args) = @_; | |
| 37 | |||
| 38 | 1 | my @report_items = qw{ min_time max_time total_time avg_time total_runs name note times }; #this is kinda janky | |
| 39 | |||
| 40 | 4 | encode_json( [ map { my $item = $_; | |
| 41 | my $x = | ||
| 42 | { ( | ||
| 43 | interp => $args{interp}, | ||
| 44 | 4 | map { $_ => $item->$_ } @report_items, | |
| 45 | ) | ||
| 46 | } | ||
| 47 | 1 | } sort {$a->total_time <=> $b->total_time} @{$args{items}}, | |
| 48 | ]); | ||
| 49 | }; | ||
| 50 | |||
| 51 | |||
| 52 | 1 | 1; | |
| 53 | |||