| 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 //= {}
MC/DC0%0/1
$grammarOptionsHashp //= {}
$grammarOptionsHashp
Truth table50%1/2
A
A= $grammarOptionsHashp
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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
| |||||||||||||
| 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__ | ||||||||||||