| 1 | #======================================================================== | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Badger::Logic | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # DESCRIPTION | ||||||||||||||||||||||||||||
| 6 | # Simple parser and evaluator for boolean logic expressions, e.g. | ||||||||||||||||||||||||||||
| 7 | # 'purple or orange', 'animal and (eats_nuts or eats_berries)' | ||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||
| 9 | # AUTHOR | ||||||||||||||||||||||||||||
| 10 | # Andy Wardley <abw@wardley.org> | ||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||
| 12 | #======================================================================== | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | package Badger::Logic; | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | use Badger::Class | ||||||||||||||||||||||||||||
| 17 | 2 | ▶ | version => 0.01, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | debug => 0, | ||||||||||||||||||||||||||||
| 19 | base => 'Badger::Base', | ||||||||||||||||||||||||||||
| 20 | as_text => 'text', | ||||||||||||||||||||||||||||
| 21 | constants => 'HASH', | ||||||||||||||||||||||||||||
| 22 | constant => { | ||||||||||||||||||||||||||||
| 23 | LOGIC => 'Badger::Logic', | ||||||||||||||||||||||||||||
| 24 | }, | ||||||||||||||||||||||||||||
| 25 | exports => { | ||||||||||||||||||||||||||||
| 26 | any => 'LOGIC Logic', | ||||||||||||||||||||||||||||
| 27 | }, | ||||||||||||||||||||||||||||
| 28 | messages => { | ||||||||||||||||||||||||||||
| 29 | no_text => 'No text expression specified.', | ||||||||||||||||||||||||||||
| 30 | no_rhs => 'Missing expression following "%s"', | ||||||||||||||||||||||||||||
| 31 | bad_text => 'Unexpected text in expression: %s', | ||||||||||||||||||||||||||||
| 32 | parse => 'Could not parse logic expression: %s', | ||||||||||||||||||||||||||||
| 33 | no_rparen => 'Missing ")" at end of nested expression', | ||||||||||||||||||||||||||||
| 34 | 2 | }; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | our $NODE = { | |||||||||||||||||||||||||||
| 37 | 'item' => 'Badger::Logic::Item', | ||||||||||||||||||||||||||||
| 38 | 'not' => 'Badger::Logic::Not', | ||||||||||||||||||||||||||||
| 39 | 'and' => 'Badger::Logic::And', | ||||||||||||||||||||||||||||
| 40 | 'or' => 'Badger::Logic::Or', | ||||||||||||||||||||||||||||
| 41 | }; | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 2 | *test = \&evaluate; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | ▶ | sub Logic { | ||||||||||||||||||||||||||
|
Subroutine
Logic: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | return @_ | ||||||||||||||||||||||||||||
| 48 | 3 | ▶ | ? LOGIC->new(@_) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | : LOGIC; | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 26 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||
| 53 | 26 | my $class = shift; | |||||||||||||||||||||||||||
| 54 | 26 | my $text = shift; | |||||||||||||||||||||||||||
| 55 | 26 | ▶ | return $class->error_msg('no_text') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | unless defined $text; | ||||||||||||||||||||||||||||
| 57 | 26 | ▶ | bless { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | text => ref $text ? $text : \$text, | ||||||||||||||||||||||||||||
| 59 | }, $class; | ||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 21 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 21 | my $self = shift; | |||||||||||||||||||||||||||
| 64 | 21 | ▶ | my $args = @_ && ref $_[0] eq HASH ? shift : { @_ }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 65 | 21 | $self->tree->evaluate($args); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 22 | ▶ | sub tree { | ||||||||||||||||||||||||||
|
Subroutine
tree: called CC=2 SCAR=8.1
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 22 | my $self = shift; | |||||||||||||||||||||||||||
| 70 | return $self->{ tree } | ||||||||||||||||||||||||||||
| 71 | 22 | ▶ | ||= $self->parse($self->{ text }); | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"tree"} ||= $self->parse($self->{"text"})
MC/DC0%0/2
$self->{"tree"} ||= $self->parse($self->{"text"})
$self->{"tree"}
$self->parse($self->{"text"})
Truth table33%1/3
A ||= B
A= $self->{"tree"}B= $self->parse($self->{"text"})
| |||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 5 | ▶ | sub text { | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 75 | 5 | ${ shift->{ text } }; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 1 | ▶ | sub tree_text { | ||||||||||||||||||||||||||
|
Subroutine
tree_text: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 1 | shift->tree->text; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 22 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||
| 83 | 22 | my $self = shift; | |||||||||||||||||||||||||||
| 84 | 22 | my $text = shift; | |||||||||||||||||||||||||||
| 85 | 22 | ▶ | my $tref = ref $text ? $text : \$text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 22 | $self->debug("parse($$tref)\n") if DEBUG; | |||||||||||||||||||||||||||
| 87 | 22 | ▶ | my $expr = $self->parse_expr($tref) | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->parse_expr($tref) || (return $self->error_msg('parse', $$tref))
MC/DC0%0/1
$self->parse_expr($tref) || (return $self->error_msg('parse', $$tref))
$self->parse_expr($tref)
Truth table50%1/2
A
A= $self->parse_expr($tref)
| |||||||||||||||||||||||||||||
| 88 | || return $self->error_msg( parse => $$tref ); | ||||||||||||||||||||||||||||
| 89 | 22 | $self->debug("expr: ", $expr->text) if DEBUG; | |||||||||||||||||||||||||||
| 90 | 22 | ▶ | if ($$tref =~ / \G \s* (.+) $/cigsx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 0 | return $self->error_msg( bad_text => $1 ); | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | 22 | return $expr; | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 73 | ▶ | sub parse_expr { | ||||||||||||||||||||||||||
|
Subroutine
parse_expr: called CC=8 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||
| 97 | 73 | my $self = shift; | |||||||||||||||||||||||||||
| 98 | 73 | my $text = shift; | |||||||||||||||||||||||||||
| 99 | 73 | ▶ | my $left = $self->parse_unary($text) || return; | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->parse_unary($text) || (return)
MC/DC0%0/1
$self->parse_unary($text) || (return)
$self->parse_unary($text)
Truth table50%1/2
A
A= $self->parse_unary($text)
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 73 | $self->debug("got unary: ", $left->text) if DEBUG; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 73 | ▶ | if ($$text =~ / \G \s+ (and|or) \s+ /cigx) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 104 | 35 | my $op = $1; | |||||||||||||||||||||||||||
| 105 | 35 | ▶ | $self->debug("binary op: $op\n") if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 35 | ▶ | my $right = $self->parse_expr($text) | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->parse_expr($text) || (return $self->error_msg('no_rhs', $op))
MC/DC0%0/1
$self->parse_expr($text) || (return $self->error_msg('no_rhs', $op))
$self->parse_expr($text)
Truth table50%1/2
A
A= $self->parse_expr($text)
| |||||||||||||||||||||||||||||
| 107 | || return $self->error_msg( no_rhs => $op ); | ||||||||||||||||||||||||||||
| 108 | 35 | return $NODE->{ lc $op }->new( $left, $right ); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | elsif ($$text =~ / \G \s* \( /cgx) { | ||||||||||||||||||||||||||||
| 111 | 0 | ▶ | my $expr = $self->parse_expr($text) | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->parse_expr($text) || (return $self->error_msg('no_rhs', '('))
MC/DC0%0/1
$self->parse_expr($text) || (return $self->error_msg('no_rhs', '('))
$self->parse_expr($text)
Truth table0%0/2
A
A= $self->parse_expr($text)
| |||||||||||||||||||||||||||||
| 112 | || return $self->error_msg( no_rhs => '(' ); | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $$text =~ / \G \s* \) /cgx | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | || return $self->error_msg('no_rparen'); | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | return $self->error_msg( bad_text => $1 ); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 38 | return $left; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 73 | ▶ | sub parse_unary { | ||||||||||||||||||||||||||
|
Subroutine
parse_unary: called CC=5 SCAR=16.7
Pod
documented
| |||||||||||||||||||||||||||||
| 123 | 73 | my $self = shift; | |||||||||||||||||||||||||||
| 124 | 73 | my $text = shift; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 73 | ▶ | if ($$text =~ / \G \s* (not) \s+ /cigx) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 13 | my $op = $1; | |||||||||||||||||||||||||||
| 128 | 13 | ▶ | $self->debug("unary op: $op\n") if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 13 | ▶ | my $right = $self->parse_term($text) | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->parse_term($text) || (return $self->error_msg('no_rhs', $op))
MC/DC0%0/1
$self->parse_term($text) || (return $self->error_msg('no_rhs', $op))
$self->parse_term($text)
Truth table50%1/2
A
A= $self->parse_term($text)
| |||||||||||||||||||||||||||||
| 130 | || return $self->error_msg( no_rhs => $op ); | ||||||||||||||||||||||||||||
| 131 | 13 | return $NODE->{ lc $op }->new($right); | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | 60 | ▶ | return $self->parse_term($text) | ||||||||||||||||||||||||||
|
Condition33%1/3
$self->parse_term($text) || $self->decline('Not a unary expression')
MC/DC0%0/2
$self->parse_term($text) || $self->decline('Not a unary expression')
$self->parse_term($text)
$self->decline('Not a unary expression')
Truth table33%1/3
A || B
A= $self->parse_term($text)B= $self->decline('Not a unary expression')
| |||||||||||||||||||||||||||||
| 134 | || $self->decline('Not a unary expression'); | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 73 | ▶ | sub parse_term { | ||||||||||||||||||||||||||
|
Subroutine
parse_term: called CC=8 SCAR=21.8
Pod
documented
| |||||||||||||||||||||||||||||
| 138 | 73 | my $self = shift; | |||||||||||||||||||||||||||
| 139 | 73 | my $text = shift; | |||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 73 | ▶ | if ($$text =~ / \G \s* (\w+) /cigx) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 142 | 54 | ▶ | $self->debug("item: $1\n") if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 54 | return $NODE->{ item }->new($1); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | elsif ($$text =~ / \G \s* (['"]) ((?:\\?.)*?) \1 /cigx) { | ||||||||||||||||||||||||||||
| 146 | 3 | ▶ | $self->debug("string: $2\n") if $DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 3 | return $NODE->{ item }->new($2); | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | elsif ($$text =~ / \G \s* \( /cgx) { | ||||||||||||||||||||||||||||
| 150 | 16 | ▶ | my $expr = $self->parse_expr($text) | ||||||||||||||||||||||||||
|
Condition50%1/2
$self->parse_expr($text) || (return $self->error_msg('no_rhs', '('))
MC/DC0%0/1
$self->parse_expr($text) || (return $self->error_msg('no_rhs', '('))
$self->parse_expr($text)
Truth table50%1/2
A
A= $self->parse_expr($text)
| |||||||||||||||||||||||||||||
| 151 | || return $self->error_msg( no_rhs => '(' ); | ||||||||||||||||||||||||||||
| 152 | 16 | ▶ | $$text =~ / \G \s* \) /cgx | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | || return $self->error_msg('no_rparen'); | ||||||||||||||||||||||||||||
| 154 | 16 | return $expr; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | return $self->decline('Not a term'); | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | #======================================================================= | ||||||||||||||||||||||||||||
| 162 | # node types | ||||||||||||||||||||||||||||
| 163 | #======================================================================= | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | package Badger::Logic::Expr; | ||||||||||||||||||||||||||||
| 166 | 2 | ▶ | use base 'Badger::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 105 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 169 | 105 | my $class = shift; | |||||||||||||||||||||||||||
| 170 | 105 | bless [ @_ ], $class; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | package Badger::Logic::Item; | ||||||||||||||||||||||||||||
| 174 | 2 | ▶ | use base 'Badger::Logic::Expr'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 41 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=3 SCAR=12.5
| |||||||||||||||||||||||||||||
| 177 | 41 | my $self = shift; | |||||||||||||||||||||||||||
| 178 | 41 | ▶ | my $args = @_ && ref $_[0] eq 'HASH' ? shift : { @_ }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ and ref $_[0] eq "HASH"
@_
ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 179 | 41 | return $args->{ $self->[0] }; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 4 | ▶ | sub text { | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 183 | 4 | $_[0]->[0]; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | package Badger::Logic::Not; | ||||||||||||||||||||||||||||
| 187 | 2 | ▶ | use base 'Badger::Logic::Expr'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 12 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 190 | 12 | my $self = shift; | |||||||||||||||||||||||||||
| 191 | 12 | ▶ | return $self->[0]->evaluate(@_) ? 0 : 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | 1 | ▶ | sub text { | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 195 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 196 | 1 | '(not ' . $self->[0]->text . ')'; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | package Badger::Logic::And; | ||||||||||||||||||||||||||||
| 200 | 2 | ▶ | use base 'Badger::Logic::Expr'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 15 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 203 | 15 | my $self = shift; | |||||||||||||||||||||||||||
| 204 | 15 | ▶ | return $self->[0]->evaluate(@_) | ||||||||||||||||||||||||||
|
Condition100%3/3
$self->[0]->evaluate(@_) && $self->[1]->evaluate(@_)
MC/DC100%2/2
$self->[0]->evaluate(@_) && $self->[1]->evaluate(@_)
$self->[0]->evaluate(@_)
$self->[1]->evaluate(@_)
Truth table100%3/3
A && B
A= $self->[0]->evaluate(@_)B= $self->[1]->evaluate(@_)
| |||||||||||||||||||||||||||||
| 205 | && $self->[1]->evaluate(@_); | ||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 2 | ▶ | sub text { | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 209 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 210 | 2 | '(' . $self->[0]->text . ' and ' . $self->[1]->text . ')'; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | package Badger::Logic::Or; | ||||||||||||||||||||||||||||
| 214 | 2 | ▶ | use base 'Badger::Logic::Expr'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 2 | ▶ | use Badger::Debug ':all'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 217 | 16 | ▶ | sub evaluate { | ||||||||||||||||||||||||||
|
Subroutine
evaluate: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 218 | 16 | my $self = shift; | |||||||||||||||||||||||||||
| 219 | 16 | ▶ | return $self->[0]->evaluate(@_) | ||||||||||||||||||||||||||
|
Condition100%3/3
$self->[0]->evaluate(@_) || $self->[1]->evaluate(@_)
MC/DC100%2/2
$self->[0]->evaluate(@_) || $self->[1]->evaluate(@_)
$self->[0]->evaluate(@_)
$self->[1]->evaluate(@_)
Truth table100%3/3
A || B
A= $self->[0]->evaluate(@_)B= $self->[1]->evaluate(@_)
| |||||||||||||||||||||||||||||
| 220 | || $self->[1]->evaluate(@_); | ||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 1 | ▶ | sub text { | ||||||||||||||||||||||||||
|
Subroutine
text: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 224 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 225 | 1 | '(' . $self->[0]->text . ' or ' . $self->[1]->text . ')'; | |||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 2 | 1; | |||||||||||||||||||||||||||
| 229 | __END__ | ||||||||||||||||||||||||||||