Scoreboard/PSGI/App/JSON.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 44 CC 2 SCAR 11.0
CC
2
Cov
0%
new
6.0
to_app
2.0
BEGIN
2.0
CRAP 3.0
1 package Parallel::Scoreboard::PSGI::App::JSON;
2  
3 use Class::Accessor::Lite;
4 use JSON qw(encode_json decode_json);
5 use Parallel::Scoreboard;
6  
7 use strict;
8 use warnings;
9  
10 Class::Accessor::Lite->mk_accessors(qw(scoreboard));
11  
12 sub new {
13 my $klass = shift;
14 my %args = @_;
15 die "mandatory parameter:scoreboard is missing"
16 unless $args{scoreboard};
17 # build object
18 my $self = bless {
19 %args,
20 }, $klass;
21 return $self;
22 }
23  
24 sub to_app {
25 my $self = shift;
26 return sub {
27 my $status = $self->scoreboard->read_all;
28 for my $s (values %$status) {
29 # try to decode status (or if fails, leave it as a string)
30 eval {
31 $s = decode_json($s);
32 };
33 }
34 return [
35 200,
36 [ 'Content-Type' => 'application/json; charset=utf-8' ],
37 [ encode_json($status) ],
38 ];
39 };
40 }
41  
42 1;
43 __END__