blib/lib/Grammar/Marpa.pm

filter: Statementstmt 90.0% 45 / 50 Branchbran 50.0% 7 / 14 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 11 / 11 Podpod 33.3% 1 / 3 totaltotal 70.9% 66 / 93 CC 11 SCAR 22.7
CC
11
Cov
74%
new
19.1
parse
2.0
BEGIN
1.0
CRAP 9.7
↑ Summary
1 package Grammar::Marpa;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use overload ('qr' => 'regexify', fallback => 0);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Marpa::R2;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = '2.004';
12  
13 1 ▶sub regexify {
Subroutine regexify: called CC=1 SCAR=0.0
Pod undocumented
14 1 my ($grammar) = @_;
15 1 ▶ use re 'eval';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 return qr/(?{Grammar::Marpa::parse($grammar, "$_")})/;
17 }
18  
19 1 ▶sub new {
Subroutine new: called CC=10 SCAR=29.5
Pod documented
20 1 my $class = shift;
21 1 ▶ $class = ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
22 1 ▶ my $ebnf = ref($_[0]) eq 'HASH' ? undef : shift(@_);
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] eq 'HASH' ? : 0 1 1
23 1 my $pkg;
24 my %args;
25 1 ▶ if (ref ($_[-1]) eq 'HASH') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[-1] eq 'HASH') { } 0 1 1
elsif (@_ % 2) { } 1 0 1
26 0 %args = %{pop(@_)};
27 0 ▶ $pkg = shift(@_) // (caller)[0];
Condition0%0/3
shift @_ // (caller)[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
shift @_ // (caller)[0]
shift @_ (caller)[0]
Truth table0%0/3
A // B
A= shift @_B= (caller)[0]
ABresult
1X1
011
000
28 }
29 elsif (@_ % 2) {
30 1 $pkg = shift;
31 1 %args = @_;
32 }
33 else {
34 0 $pkg = (caller)[0];
35 0 %args = @_;
36 }
37 1 my %Gargs;
38 1 ▶ $Gargs{ bless_package } = delete $args{ bless_package } if $args{ bless_package };
Branch: 1 branch
BranchTrueFalseTotal
if $args{"bless_package"} 0 1 1
39 1 ▶ $Gargs{ trace_file_handle } = $args{ trace_file_handle } if $args{ trace_file_handle };
Branch: 1 branch
BranchTrueFalseTotal
if $args{"trace_file_handle"} 0 1 1
40 1 ▶ $ebnf //= delete $args{ source };
Condition33%1/3
$ebnf //= delete $args{"source"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$ebnf //= delete $args{"source"}
$ebnf delete $args{"source"}
Truth table33%1/3
A //= B
A= $ebnfB= delete $args{"source"}
ABresult
1X1
011
000
41 1 ▶ $ebnf = $$ebnf if ref($ebnf);
Branch: 1 branch
BranchTrueFalseTotal
if ref $ebnf 0 1 1
42 1 my $G = Marpa::R2::Scanless::G->new({ source => \$ebnf, %Gargs });
43 1 return bless [ $G, $pkg, \%args ] => $class;
44 }
45  
46 1 ▶sub parse {
Subroutine parse: called CC=2 SCAR=7.0
Pod undocumented
47 1 my ($grammar, $string) = @_;
48 1 my $R = Marpa::R2::Scanless::R->new({ grammar => $grammar->[ 0 ], semantics_package => $grammar->[ 1 ], %{$grammar->[ 2 ]} });
49 1 $R->read(\$string);
50 1 ▶ my $V = $R->value or return;
Branch: 1 branch
BranchTrueFalseTotal
my $V = $R->value or return 1 0 1
51 1 return $$V;
52 }
53  
54 package Grammar;
55  
56 1 ▶sub Marpa {
Subroutine Marpa: called CC=1 SCAR=0.0
57 1 return Grammar::Marpa->new(@_);
58 }
59  
60 1 1;
61  
62 __END__
↑ Summary