Google/Parser.pm

filter: Statementstmt 96.1% 25 / 26 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 8 totaltotal 75.5% 37 / 49 CC 4 SCAR 4.2
CC
4
Cov
88%
make_filter
2.1
object
2.1
parse
2.0
CRAP 1.5
« Google.pm ↑ Summary
1 package Data::Partial::Google::Parser;
2 3 our $VERSION = '0.02'; # VERSION
3 3 our $AUTHORITY = 'cpan:ARODLAND'; # AUTHORITY
4 3 ▶use Marpa::R2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 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 3 my $grammar = Marpa::R2::Scanless::G->new({
26 source => \$rules,
27 bless_package => 'Data::Partial::Google',
28 });
29  
30 26 ▶sub parse {
Subroutine parse: called CC=2 SCAR=7.1
Pod undocumented
31 26 my ($class, $input) = @_;
32  
33 26 my $recognizer = Marpa::R2::Scanless::R->new({
34 semantics_package => $class,
35 grammar => $grammar,
36 });
37  
38 26 $recognizer->read(\$input);
39 26 my $value = $recognizer->value;
40 26 ▶ if ($value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value) { } 26 0 26
41 26 return $$value;
42 } else {
43 0 return undef;
44 }
45 }
46  
47 51 ▶sub make_filter {
Subroutine make_filter: called CC=2 SCAR=7.2
Pod undocumented
48 51 my ($properties) = @_;
49 51 ▶ return bless {
Branch: 1 branch
BranchTrueFalseTotal
$properties ? : 51 0 51
50 ($properties
51 ? (properties => $properties)
52 : ()
53 )
54 }, 'Data::Partial::Google::Filter';
55 }
56  
57 51 ▶sub merge_props {
Subroutine merge_props: called CC=1 SCAR=0.0
Pod undocumented
58 # Turn [[a, Filter], [b, Filter], [c, Filter]]
59 # into { a => Filter, b => Filter, c => Filter }
60
61 return +{
62 51 map { @$_ } @_
63 };
64 }
65  
66 26 ▶sub toplevel {
Subroutine toplevel: called CC=1 SCAR=0.0
Pod undocumented
67 26 make_filter($_[1]);
68 }
69  
70 35 ▶sub props {
Subroutine props: called CC=1 SCAR=0.0
Pod undocumented
71 35 shift; # Unused global object
72 35 merge_props(@_);
73 }
74  
75 16 ▶sub object {
Subroutine object: called CC=2 SCAR=7.2
Pod undocumented
76 16 ▶ my $props = $_[2] ? merge_props($_[2]) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 16 0 16
77  
78 16 [ $_[1], make_filter($props) ]
79 }
80  
81 42 ▶sub leaf {
Subroutine leaf: called CC=1 SCAR=0.0
Pod undocumented
82 42 [ $_[1], undef ]
83 }
84  
85 9 ▶sub array {
Subroutine array: called CC=1 SCAR=0.0
Pod undocumented
86 9 [ $_[1], make_filter($_[2]) ]
87 }
88  
89 3 1;
90  
91 __END__
« Google.pm ↑ Summary