File Coverage

blib/lib/Pegex/JSON/Data.pm
Criterion Covered Total %
statement 17 23 73.9
branch n/a
condition n/a
subroutine 5 10 50.0
pod 0 8 0.0
total 22 41 53.6


line stmt bran cond sub pod time code
1             package Pegex::JSON::Data;
2 2     2   14 use Pegex::Base;
  2         6  
  2         11  
3             extends 'Pegex::Tree';
4              
5 2     2   3658 use boolean;
  2         4707  
  2         10  
6              
7 3     3 0 436 sub got_json { $_[1][0] }
8 0     0 0 0 sub got_object { +{map @$_, map @$_, @{(pop)}} }
  0         0  
9 3     3 0 610 sub got_array { [map @$_, @{(pop)}] }
  3         15  
10              
11             my %escapes = (
12             '"' => '"',
13             '/' => "/",
14             "\\" => "\\",
15             b => "\b",
16             f => "\x12",
17             n => "\n",
18             r => "\r",
19             t => "\t",
20             );
21              
22             sub got_string {
23 3     3 0 6789 my $string = pop;
24 3         15 $string =~ s/\\(["\/\\bfnrt])/$escapes{$1}/ge;
  2         33  
25             # This handles JSON encoded Unicode surrogate pairs
26 3         10 $string =~ s/\\u([0-9a-f]{4})\\u([0-9a-f]{4})/pack "U*", hex("$1$2")/ge;
  1         9  
27 3         11 $string =~ s/\\u([0-9a-f]{4})/pack "U*", hex($1)/ge;
  1         13  
28 3         14 return $string;
29             }
30              
31 0     0 0   sub got_number { $_[1] + 0 }
32 0     0 0   sub got_true { &boolean::true }
33 0     0 0   sub got_false { &boolean::false }
34 0     0 0   sub got_null { undef }
35              
36             1;