File Coverage

blib/lib/Pegex/JSON/Data.pm
Criterion Covered Total %
statement 16 22 72.7
branch n/a
condition n/a
subroutine 4 9 44.4
pod 0 7 0.0
total 20 38 52.6


line stmt bran cond sub pod time code
1             package Pegex::JSON::Data;
2 2     2   15 use Pegex::Base;
  2         7  
  2         13  
3             extends 'Pegex::Tree';
4              
5 2     2   3502 use boolean;
  2         4598  
  2         9  
6              
7 3     3 0 1034 sub got_json { shift @{(pop)} }
  3         10  
8              
9 0     0 0 0 sub got_object { +{map @$_, @{(pop)}} }
  0         0  
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 6511 my $string = pop;
24 3         14 $string =~ s/\\(["\/\\bfnrt])/$escapes{$1}/ge;
  2         32  
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         9 $string =~ s/\\u([0-9a-f]{4})/pack "U*", hex($1)/ge;
  1         14  
28 3         14 return $string;
29             }
30              
31 0     0 0   sub got_number { (pop) + 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;