AST/Impl/Singleton.pm

filter: Statementstmt 84.4% 38 / 45 Branchbran 33.3% 2 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 79.6% 51 / 64 CC 6 SCAR 15.0
CC
6
Cov
77%
G
9.2
BEGIN
1.0
BEGIN
1.0
CRAP 4.5
« AST/Grammar/ECMAScript_262_5/Pattern.pm ↑ Summary AST/Grammar/ECMAScript_262_5/SpacesAny.pm »
1 18 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 18 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package MarpaX::Languages::ECMAScript::AST::Impl::Singleton;
5 18 ▶use base 'Class::Singleton';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 18 ▶use Sereal qw/encode_sereal decode_sereal/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 18 ▶use Data::Compare qw//;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 18 ▶use Marpa::R2 2.078000;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 18 ▶use Log::Any qw/$log/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # ABSTRACT: Singleton hosting all the grammar precompiled Marpa::R2::Scanless::G objects
12  
13 18 our $VERSION = '0.020'; # VERSION
14  
15  
16 17 ▶sub _new_instance {
Subroutine _new_instance: called CC=1 SCAR=0.0
17 17 my ($class) = @_;
18 17 my $self = bless {_G => {} }, $class;
19 17 return $self;
20 }
21  
22  
23 6 ▶sub G {
Subroutine G: called CC=6 SCAR=22.1
Pod documented
24 6 my ($self, $grammarOptionsHashp) = @_;
25  
26 6 ▶ $grammarOptionsHashp //= {};
Condition50%1/2
$grammarOptionsHashp //= {}
l!l
60
MC/DC0%0/1
$grammarOptionsHashp //= {}
$grammarOptionsHashp
Truth table50%1/2
A
A= $grammarOptionsHashp
Aresult
11
00
27  
28 #
29 # Search the key
30 #
31 6 my $key = undef;
32 6 foreach (keys %{$self->{_G}}) {
33 0 my $thisKey = $_;
34 0 my $thisOptionsHashp = decode_sereal($thisKey);
35 0 my $c = new Data::Compare($grammarOptionsHashp, $thisOptionsHashp);
36 0 ▶ if ($c->Cmp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->Cmp) 0 0 0
37 0 $key = $thisKey;
38 0 last;
39 }
40 }
41 #
42 # Create a new key if necessary
43 #
44 6 ▶ if (! defined($key)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $key) 6 0 6
45 6 $log->debugf('Creating grammar key');
46 6 $key = encode_sereal($grammarOptionsHashp);
47 }
48  
49 6 ▶ if (! defined($self->{_G}->{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'_G'}{$key}) { } 6 0 6
50 #
51 # Create the grammar object
52 #
53 6 $log->debugf('Creating grammar object');
54 6 $self->{_G}->{$key} = Marpa::R2::Scanless::G->new($grammarOptionsHashp);
55 } else {
56 0 $log->debugf('Found cached grammar object');
57 }
58  
59 6 return $self->{_G}->{$key};
60 }
61  
62 18 1;
63  
64 __END__
« AST/Grammar/ECMAScript_262_5/Pattern.pm ↑ Summary AST/Grammar/ECMAScript_262_5/SpacesAny.pm »