| 1 | 5 | ▶ | use v5.26; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 5 | ▶ | use Object::Pad; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | |||||||||||||||
| 4 | 5 | ▶ | use Getopt::Pad::Config::Format; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | class Getopt::Pad::Config::Format::Json :isa(Getopt::Pad::Config::Format) :strict(params) { | ||||||||||||||
| 7 | 5 | ▶ | use JSON::PP (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 5 | our $VERSION = '0.06'; | |||||||||||||
| 10 | |||||||||||||||
| 11 | 5 | ▶ | use constant NAMES => ['json']; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | # An empty file sets nothing. Values arrive as plain scalars, as YAML | ||||||||||||||
| 14 | # gives them: booleans as 1 and 0, so a string option set to true reads | ||||||||||||||
| 15 | # 1, not an object; numbers as written, so a large integer is not | ||||||||||||||
| 16 | # rounded to a float before a bigint option sees it. | ||||||||||||||
| 17 | 10 | ▶ | method parse($text) { | ||||||||||||
|
Subroutine
parse: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 18 | 10 | ▶ | return {} if $text !~ /\S/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 19 | 8 | return $self->plainScalars(JSON::PP->new->allow_bignum->decode($text)); | |||||||||||||
| 20 | 5 | } | |||||||||||||
| 21 | |||||||||||||||
| 22 | 26 | ▶ | method plainScalars($data) { | ||||||||||||
|
Subroutine
plainScalars: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||
| 23 | 26 | ▶ | return [map { $self->plainScalars($_) } $data->@*] if ref $data eq 'ARRAY'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | 25 | ▶ | return { map { $_ => $self->plainScalars($data->{$_}) } keys $data->%* } if ref $data eq 'HASH'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | 11 | ▶ | return $data ? 1 : 0 if JSON::PP::is_bool($data); | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 26 | 8 | ▶ | return "$data" if ref $data; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 4 | return $data; | |||||||||||||
| 28 | 5 | } | |||||||||||||
| 29 | |||||||||||||||
| 30 | 2 | ▶ | method dump($data) { | ||||||||||||
|
Subroutine
dump: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 31 | 2 | return JSON::PP->new->pretty->canonical->encode($data); | |||||||||||||
| 32 | 5 | } | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | |||||||||||||||
| 35 | 5 | 1; | |||||||||||||
| 36 | |||||||||||||||
| 37 | __END__ | ||||||||||||||