File Coverage

blib/lib/Pegex/JSON/Data.pm
Criterion Covered Total %
statement 23 23 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 0 8 0.0
total 33 41 80.4


line stmt bran cond sub pod time code
1             package Pegex::JSON::Data;
2 3     3   20 use Pegex::Base;
  3         6  
  3         23  
3             extends 'Pegex::Tree';
4              
5 3     3   11805 use boolean;
  3         12387  
  3         19  
6              
7 18     18 0 2631 sub got_json { $_[1][0] }
8 6     6 0 3620 sub got_object { +{map @$_, map @$_, @{(pop)}} }
  6         65  
9 13     13 0 5107 sub got_array { [map @$_, @{(pop)}] }
  13         97  
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 14     14 0 27953 my $string = pop;
24 14         46 $string =~ s/\\(["\/\\bfnrt])/$escapes{$1}/ge;
  2         9  
25             # This handles JSON encoded Unicode surrogate pairs
26 14         31 $string =~ s/\\u([0-9a-f]{4})\\u([0-9a-f]{4})/pack "U*", hex("$1$2")/ge;
  1         9  
27 14         27 $string =~ s/\\u([0-9a-f]{4})/pack "U*", hex($1)/ge;
  1         10  
28 14         70 return $string;
29             }
30              
31 28     28 0 17910 sub got_number { $_[1] + 0 }
32 2     2 0 2645 sub got_true { &boolean::true }
33 1     1 0 397 sub got_false { &boolean::false }
34 2     2 0 2616 sub got_null { undef }
35              
36             1;