| 1 | package Locale::Simple::PO2JSON; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Convert a gettext PO file to the JSON data Locale::Simple reads in the browser | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 24 | our $VERSION = '0.200'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 24 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 24 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 24 | ▶ | use Encode (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 24 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 24 | ▶ | use JSON::PP (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 24 | our @EXPORT_OK = qw( po2data data2json ); | |||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 24 | my %ESCAPE = ( | |||||||||||||||||||||||||||||||||||||||||
| 15 | n => "\n", t => "\t", r => "\r", a => "\a", | ||||||||||||||||||||||||||||||||||||||||||
| 16 | b => "\b", f => "\f", v => "\x0b", '\\' => '\\', '"' => '"', | ||||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 689 | ▶ | sub _unquote { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unquote: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 689 | my ( $path, $n, $str ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 689 | $str =~ s{\\(?:([ntrabfv\\"])|([0-7]{1,3})|x([0-9a-fA-F]{1,2})|(.))}{ | |||||||||||||||||||||||||||||||||||||||||
| 22 | 170 | ▶ | defined $1 ? $ESCAPE{$1} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | : defined $2 ? chr( oct $2 ) | ||||||||||||||||||||||||||||||||||||||||||
| 24 | : defined $3 ? chr( hex $3 ) | ||||||||||||||||||||||||||||||||||||||||||
| 25 | : die "$path line $n: unknown escape sequence \\$4\n" | ||||||||||||||||||||||||||||||||||||||||||
| 26 | }gse; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 688 | return $str; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # One or more quoted strings on a line, as msgfmt reads them: "a" "b" is "ab". | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 24 | my $STR = qr/"(?:[^"\\]|\\.)*"/; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 24 | my $STRS = qr/$STR(?:\s*$STR)*/; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 684 | ▶ | sub _unquote_all { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unquote_all: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 684 | my ( $path, $n, $strings ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 36 | 684 | my $val = ''; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 684 | ▶ | $val .= _unquote( $path, $n, $1 ) while $strings =~ /"((?:[^"\\]|\\.)*)"/g; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 683 | return $val; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 34 | ▶ | sub _read_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_file: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 34 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 34 | ▶ | open my $fh, '<:raw', $path or die "Cannot read PO file $path: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 29 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 29 | my $raw = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 46 | 29 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 47 | 29 | ▶ | $raw = '' unless defined $raw; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 29 | $raw =~ s/\A\xEF\xBB\xBF//; | |||||||||||||||||||||||||||||||||||||||||
| 49 | 29 | my $text = eval { Encode::decode( 'UTF-8', $raw, Encode::FB_CROAK() ) }; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 29 | ▶ | die "Cannot read PO file $path: not valid UTF-8\n" unless defined $text; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 28 | return $text; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 20 | ▶ | sub _parse_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_header: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 20 | my ($msgstr) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 20 | my %h; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 20 | for my $line ( split /\n/, $msgstr ) { | |||||||||||||||||||||||||||||||||||||||||
| 58 | 179 | ▶ | next unless $line =~ /\A([^:]+):(.*)\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 179 | my ( $k, $v ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||
| 60 | 179 | s/\A\s+|\s+\z//g for $k, $v; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 179 | $h{$k} = $v; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 20 | ▶ | $h{lang} = $h{Language} if defined $h{Language} && length $h{Language}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $h{"Language"} and length $h{"Language"}
MC/DC50%1/2
defined $h{"Language"} and length $h{"Language"}
defined $h{"Language"}
length $h{"Language"}
Truth table66%2/3
A and B
A= defined $h{"Language"}B= length $h{"Language"}
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 20 | return \%h; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 34 | ▶ | sub po2data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
po2data: called CC=32 SCAR=34.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 34 | my ( $path, %opt ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 34 | my $text = _read_file($path); | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 28 | my ( %entries, $header, $has_plural ); | |||||||||||||||||||||||||||||||||||||||||
| 72 | 28 | my ( $cur, $field, $flags, $cur_flags ) = ( undef, undef, {} ); | |||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 170 | ▶ | my $finish = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 170 | ▶ | return unless $cur; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 167 | my $e = $cur; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 167 | undef $cur; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 167 | undef $field; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 167 | ▶ | my @str = map { defined $_ ? $_ : '' } @{ $e->{msgstr} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 167 | ▶ | if ( !defined $e->{msgctxt} && $e->{msgid} eq '' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $e->{"msgctxt"} and $e->{"msgid"} eq ""
MC/DC100%2/2
not defined $e->{"msgctxt"} and $e->{"msgid"} eq ""
not defined $e->{"msgctxt"}
$e->{"msgid"} eq ""
Truth table100%3/3
not(A) and B
A= not defined $e->{"msgctxt"}B= $e->{"msgid"} eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 20 | ▶ | $header = _parse_header( $str[0] // '' ); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$str[0] // ""
MC/DC0%0/1
$str[0] // ""
$str[0]
Truth table50%1/2
A
A= $str[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 20 | return; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 147 | ▶ | return if $cur_flags->{fuzzy}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 146 | ▶ | return unless @str && length $str[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@str and length $str[0]
MC/DC50%1/2
@str and length $str[0]
@str
length $str[0]
Truth table66%2/3
A and B
A= @strB= length $str[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 145 | ▶ | $has_plural = 1 if defined $e->{msgid_plural}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 145 | ▶ | my $key = defined $e->{msgctxt} ? "$e->{msgctxt}\x04$e->{msgid}" : $e->{msgid}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 145 | $entries{$key} = [ $e->{msgid_plural}, @str ]; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 28 | }; | |||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | 28 | my $n = 0; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 28 | for my $line ( split /\r?\n/, $text ) { | |||||||||||||||||||||||||||||||||||||||||
| 93 | 841 | $n++; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 841 | ▶ | if ( $line =~ /\A\s*\z/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 148 | $finish->(); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 148 | $flags = {}; | |||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | elsif ( $line =~ /\A\s*#~/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # obsolete entry, including #~| previous msgids | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | $finish->(); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | $flags = {}; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | elsif ( $line =~ /\A\s*#(.?)(.*)\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 5 | my ( $kind, $rest ) = ( $1, $2 ); | |||||||||||||||||||||||||||||||||||||||||
| 105 | 5 | ▶ | $finish->() if $cur && $field =~ /\Amsgstr/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$cur and $field =~ /\Amsgstr/
MC/DC0%0/2
$cur and $field =~ /\Amsgstr/
$cur
$field =~ /\Amsgstr/
Truth table33%1/3
A and B
A= $curB= $field =~ /\Amsgstr/
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 5 | ▶ | if ( $kind eq ',' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 2 | $flags->{$_} = 1 for grep { length } split /[\s,]+/, $rest; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | elsif ( $line =~ /\A\s*(msgctxt|msgid_plural|msgid|msgstr(?:\[(\d+)\])?)\s*($STRS)\s*\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 501 | my ( $kw, $idx, $val ) = ( $1, $2, _unquote_all( $path, $n, $3 ) ); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 500 | ▶ | if ( $kw eq 'msgctxt' || $kw eq 'msgid' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$kw eq "msgctxt" or $kw eq "msgid"
MC/DC100%2/2
$kw eq "msgctxt" or $kw eq "msgid"
$kw eq "msgctxt"
$kw eq "msgid"
Truth table100%3/3
A or B
A= $kw eq "msgctxt"B= $kw eq "msgid"
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 189 | ▶ | $finish->() if $cur && $field =~ /\Amsgstr/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cur and $field =~ /\Amsgstr/
MC/DC0%0/2
$cur and $field =~ /\Amsgstr/
$cur
$field =~ /\Amsgstr/
Truth table66%2/3
A and B
A= $curB= $field =~ /\Amsgstr/
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 189 | ▶ | if ( !$cur ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 170 | $cur = { msgstr => [] }; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 170 | $cur_flags = $flags; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 170 | $flags = {}; | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | die "$path line $n: $kw not allowed here\n" | ||||||||||||||||||||||||||||||||||||||||||
| 120 | if defined $cur->{$kw} | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 189 | ▶ | || ( $kw eq 'msgctxt' && defined $cur->{msgid} ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $cur->{$kw} or $kw eq "msgctxt" and defined $cur->{"msgid"}
$kw eq "msgctxt" and defined $cur->{"msgid"}
MC/DC100%3/3
defined $cur->{$kw} or $kw eq "msgctxt" and defined $cur->{"msgid"}
defined $cur->{$kw}
$kw eq "msgctxt"
defined $cur->{"msgid"}
Truth table100%4/4
A or B and C
A= defined $cur->{$kw}B= $kw eq "msgctxt"C= defined $cur->{"msgid"}
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 187 | $cur->{$kw} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 187 | $field = $kw; | |||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | elsif ( $kw eq 'msgid_plural' ) { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | die "$path line $n: msgid_plural without msgid\n" | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 71 | ▶ | unless $cur && defined $cur->{msgid}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cur and defined $cur->{"msgid"}
MC/DC50%1/2
$cur and defined $cur->{"msgid"}
$cur
defined $cur->{"msgid"}
Truth table66%2/3
A and B
A= $curB= defined $cur->{"msgid"}
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 70 | $cur->{msgid_plural} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 70 | $field = $kw; | |||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 132 | die "$path line $n: $kw without msgid\n" | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 240 | ▶ | unless $cur && defined $cur->{msgid}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cur and defined $cur->{"msgid"}
MC/DC50%1/2
$cur and defined $cur->{"msgid"}
$cur
defined $cur->{"msgid"}
Truth table66%2/3
A and B
A= $curB= defined $cur->{"msgid"}
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 238 | ▶ | $idx = 0 unless defined $idx; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 238 | $cur->{msgstr}[$idx] = $val; | |||||||||||||||||||||||||||||||||||||||||
| 136 | 238 | $field = "msgstr[$idx]"; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | elsif ( $line =~ /\A\s*($STRS)\s*\z/ ) { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 184 | ▶ | die "$path line $n: string without keyword\n" unless $cur && defined $field; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cur and defined $field
MC/DC50%1/2
$cur and defined $field
$cur
defined $field
Truth table66%2/3
A and B
A= $curB= defined $field
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 183 | my $val = _unquote_all( $path, $n, $1 ); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 183 | ▶ | if ( $field =~ /\Amsgstr\[(\d+)\]\z/ ) { $cur->{msgstr}[$1] .= $val } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | else { $cur->{$field} .= $val } | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | die "$path line $n: syntax error\n"; | |||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 20 | $finish->(); | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 20 | ▶ | $header ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$header ||= {}
MC/DC0%0/1
$header ||= {}
$header
Truth table50%1/2
A
A= $header
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | warn "$path: no Plural-Forms header, keeping the plural forms as found\n" | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 20 | ▶ | if $has_plural && !defined $header->{'Plural-Forms'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$has_plural and not defined $header->{"Plural-Forms"}
MC/DC100%2/2
$has_plural and not defined $header->{"Plural-Forms"}
$has_plural
not defined $header->{"Plural-Forms"}
Truth table100%3/3
A and not(B)
A= $has_pluralB= not defined $header->{"Plural-Forms"}
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 20 | my $data = { '' => $header, %entries }; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 20 | ▶ | $data = { $opt{domain} => $data } if defined $opt{domain}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 20 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 21 | ▶ | sub data2json { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data2json: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 21 | my ( $data, %opt ) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 21 | my $json = JSON::PP->new->canonical->utf8; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 21 | ▶ | $json->pretty if $opt{pretty}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 21 | my $out = $json->encode($data); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 21 | $out =~ s/\n\z//; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 21 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 24 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | __END__ | ||||||||||||||||||||||||||||||||||||||||||