line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Flux::Format::JSON; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: JSON format for flux storages |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 SYNOPSIS |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Flux::Format::JSON; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $json_storage = Flux::Format::JSON->wrap($storage); |
10
|
|
|
|
|
|
|
$json_storage->write({ foo => "bar" }); # will be serialized correctly, even if underlying $storage can only store strings ending with \n |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $in = $json_storage->in(...); |
13
|
|
|
|
|
|
|
$in->read; # { foo => "bar" } |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=cut |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
1603718
|
use Moo; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
9
|
|
18
|
|
|
|
|
|
|
with 'Flux::Format'; |
19
|
|
|
|
|
|
|
|
20
|
1
|
|
|
1
|
|
2216
|
use JSON; |
|
1
|
|
|
|
|
50774
|
|
|
1
|
|
|
|
|
15
|
|
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
1
|
|
1970
|
use Flux::Simple qw(mapper); |
|
1
|
|
|
|
|
26536
|
|
|
1
|
|
|
|
|
262
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has 'json' => ( |
25
|
|
|
|
|
|
|
is => 'lazy', |
26
|
|
|
|
|
|
|
default => sub { |
27
|
|
|
|
|
|
|
return JSON->new->utf8->allow_nonref; |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub encoder { |
32
|
3
|
|
|
3
|
0
|
23106
|
my $self = shift; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return mapper { |
35
|
3
|
|
|
3
|
|
3632
|
my $item = shift; |
36
|
3
|
|
|
|
|
58
|
return $self->json->encode($item)."\n"; |
37
|
3
|
|
|
|
|
35
|
}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub decoder { |
41
|
3
|
|
|
3
|
0
|
54261
|
my $self = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
return mapper { |
44
|
3
|
|
|
3
|
|
46884
|
my $item = shift; |
45
|
|
|
|
|
|
|
|
46
|
3
|
|
|
|
|
81
|
return $self->json->decode($item); |
47
|
3
|
|
|
|
|
34
|
}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |