Highlife/Rule/Optional.pm

filter: Statementstmt 46.4% 13 / 28 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 2 totaltotal 43.5% 17 / 39 CC 2 SCAR 9.2
CC
2
Cov
43%
parse_from_token
6.0
new
2.0
_init
2.0
CRAP 2.5
« Highlife/Token/Regex.pm ↑ Summary Highlife/Code.pm »
1 package Parse::Highlife::Rule::Optional;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use base qw(Parse::Highlife::Rule);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Parse::Highlife::Utils qw(params);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Data::Dump qw(dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub new
9 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
10 0 my( $class, @args ) = @_;
11 0 my $self = bless Parse::Highlife::Rule->new( @args ), $class;
12 0 return $self -> _init( @args );
13 }
14  
15 sub _init
16 0 ▶{
Subroutine _init: not called CC=1 SCAR=6.9
17 0 my( $self, $optional )
18 = params( \@_,
19 -optional => '',
20 );
21 0 $self->{'optional'} = $optional;
22 0 return $self;
23 }
24  
25 sub parse_from_token
26 0 ▶{
Subroutine parse_from_token: not called CC=2 SCAR=17.9
Pod undocumented
27 0 my( $self, $parser, $tokens, $t ) = @_;
28 # - turn list of subrules into a single SEQ() rule
29 # - try to parse SEQ() rule
30 # - on success: return result, else return failure
31  
32 0 my $subrule = $parser->get_rule( $self->{'optional'} );
33  
34 0 my $_t = $t;
35 0 my ($_status, $_result);
36 0 ($_t) = $self->_parse_ignored_tokens( $tokens, $_t );
37 0 ($_status, $_t, $_result) = $subrule->wrap_parse_from_token( $parser, $tokens, $_t );
38  
39 0 ▶ if( $_status ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_status) 0 0 0
40 return (
41 1,
42 $_t,
43 0 $parser->make_ast_element('group', $self->{'name'}, [ $_result ])
44 );
45 }
46 return (
47 1,
48 $t,
49 0 $parser->make_ast_element('group', $self->{'name'}, [])
50 ); # always succeeds, since its optional
51 }
52  
53 1 1;
« Highlife/Token/Regex.pm ↑ Summary Highlife/Code.pm »