File Coverage

blib/lib/Data/Partial/Google/Parser.pm
Criterion Covered Total %
statement 20 21 95.2
branch 3 6 50.0
condition n/a
subroutine 9 9 100.0
pod 0 8 0.0
total 32 44 72.7


line stmt bran cond sub pod time code
1             package Data::Partial::Google::Parser;
2             our $VERSION = '0.02'; # VERSION
3             our $AUTHORITY = 'cpan:ARODLAND'; # AUTHORITY
4 3     3   122939 use Marpa::R2;
  3         598146  
  3         1208  
5              
6             my $rules = q{
7             lexeme default = latm => 1
8             :default ::= action => [values]
9              
10             TopLevel ::= Props action => toplevel
11              
12             Props ::= Prop+ separator => [,] action => props
13              
14             Prop ::= Object action => ::first bless => ::undef
15             | Array action => ::first bless => ::undef
16              
17             Object ::= NAME action => leaf
18             | NAME ('/') Prop action => object
19              
20             Array ::= NAME ('(') Props (')') action => array
21              
22             NAME ~ [^,/()]+
23             };
24              
25             my $grammar = Marpa::R2::Scanless::G->new({
26             source => \$rules,
27             bless_package => 'Data::Partial::Google',
28             });
29              
30             sub parse {
31 26     26 0 26935 my ($class, $input) = @_;
32              
33 26         403 my $recognizer = Marpa::R2::Scanless::R->new({
34             semantics_package => $class,
35             grammar => $grammar,
36             });
37              
38 26         8501 $recognizer->read(\$input);
39 26         6622 my $value = $recognizer->value;
40 26 50       1013 if ($value) {
41 26         1585 return $$value;
42             } else {
43 0         0 return undef;
44             }
45             }
46              
47             sub make_filter {
48 51     51 0 117 my ($properties) = @_;
49 51 50       481 return bless {
50             ($properties
51             ? (properties => $properties)
52             : ()
53             )
54             }, 'Data::Partial::Google::Filter';
55             }
56              
57             sub merge_props {
58             # Turn [[a, Filter], [b, Filter], [c, Filter]]
59             # into { a => Filter, b => Filter, c => Filter }
60            
61             return +{
62 51     51 0 100 map { @$_ } @_
  67         518  
63             };
64             }
65              
66             sub toplevel {
67 26     26 0 944 make_filter($_[1]);
68             }
69              
70             sub props {
71 35     35 0 1237 shift; # Unused global object
72 35         218 merge_props(@_);
73             }
74              
75             sub object {
76 16 50   16 0 641 my $props = $_[2] ? merge_props($_[2]) : undef;
77              
78 16         68 [ $_[1], make_filter($props) ]
79             }
80              
81             sub leaf {
82 42     42 0 58491 [ $_[1], undef ]
83             }
84              
85             sub array {
86 9     9 0 322 [ $_[1], make_filter($_[2]) ]
87             }
88              
89             1;
90              
91             __END__