RandGen/Subrule.pm

filter: Statementstmt 74.0% 40 / 54 Branchbran 47.0% 16 / 34 Conditioncond 66.6% 6 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 75.0% 9 / 12 Podpod 57.1% 4 / 7 totaltotal 64.7% 79 / 122 CC 21 SCAR 28.3
CC
21
Cov
64%
dump
56.0
pick
10.0
subrule
7.5
CRAP 17.0
« RandGen/Condition.pm ↑ Summary RandGen/Rule.pm »
1 # $Revision: #4 $$Date: 2005/08/31 $$Author: jd150722 $
2 ######################################################################
3 #
4 # This program is Copyright 2003-2005 by Jeff Dutton.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of either the GNU General Public License or the
8 # Perl Artistic License.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # If you do not have a copy of the GNU General Public License write to
16 # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
17 # MA 02139, USA.
18 ######################################################################
19  
20 package Parse::RandGen::Subrule;
21  
22 4 require 5.006_001;
23 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 4 ▶use Parse::RandGen qw($Debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 4 ▶use vars qw(@ISA $Debug);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 4 @ISA = ('Parse::RandGen::Condition');
28  
29 3 ▶sub _newDerived { } # Nothing to do
Subroutine _newDerived: called CC=1 SCAR=0.0
30  
31 0 ▶sub isSubrule { return 1; }
Subroutine isSubrule: not called CC=1 SCAR=6.9
Pod documented
32 0 ▶sub isTerminal { return 0; }
Subroutine isTerminal: not called CC=1 SCAR=6.9
Pod documented
33 104 ▶sub isQuantSupported { return 1; }
Subroutine isQuantSupported: called CC=1 SCAR=0.0
Pod undocumented
34  
35 404 ▶sub subrule {
Subroutine subrule: called CC=5 SCAR=20.2
Pod documented
36 404 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 404 0 404
37 404 my $subrule = $self->element();
38 404 ▶ if (ref($subrule)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $subrule) { } 404 0 404
39 404 ▶ UNIVERSAL::isa($subrule, "Parse::RandGen::Rule") or confess("subrule() contains a reference ($subrule), but it is not a Rule!");
Branch: 1 branch
BranchTrueFalseTotal
UNIVERSAL::isa($subrule, "Parse::RandGen::Rule") or confess("subrule() contains a reference ($subrule), but it is not a Rule!") 404 0 404
40 404 return($subrule);
41 } else {
42 0 ▶ defined($self->grammar()) or confess ("%Error: Parse::RandGen::Subrule::subrule() called, but the \"$subrule\" rule cannot be found, because grammar() is undef!");
Branch: 1 branch
BranchTrueFalseTotal
defined $self->grammar or confess(qq[%Error: Parse::RandGen::Subrule::subrule() called, but the "$subrule" rule cannot be found, because grammar() is undef!]) 0 0 0
43 0 return($self->grammar()->rule($subrule));
44 }
45 }
46  
47 0 ▶sub dump {
Subroutine dump: not called CC=7 SCAR=40.3
Pod undocumented
48 0 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 0 0 0
49 0 my $subrule = $self->element();
50 0 ▶ if (ref($subrule)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $subrule) { } 0 0 0
51 0 return ($subrule->dumpHeir() . $self->quant());
52 } else {
53 # Named non-reference rule
54 0 my $output = $subrule;
55 0 ▶ if (defined($self->max()) && ($self->min() == $self->max())) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->max and $self->min == $self->max) { } 0 0 0
Condition0%0/3
defined $self->max and $self->min == $self->max
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->max and $self->min == $self->max
defined $self->max $self->min == $self->max
Truth table0%0/3
A and B
A= defined $self->maxB= $self->min == $self->max
ABresult
0X0
100
111
56 0 ▶ $output .= "(" . $self->min() . ")" unless ($self->min() == 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->min == 1 0 0 0
57 } else {
58 0 ▶ my $max = defined($self->max()) ? $self->max() : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $self->max ? : 0 0 0
59 0 $output .= "(" . $self->min() . ".." . $max . ")";
60 }
61 0 return $output;
62 }
63 }
64  
65 202 ▶sub pick {
Subroutine pick: called CC=10 SCAR=23.0
Pod documented
66 202 ▶ my $self = shift or confess ("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 202 0 202
67 202 my %args = ( match=>1, # Default is to pick matching data
68 @_ );
69 202 my $rule = $self->subrule();
70 202 my $ruleName = $self->element();
71 202 ▶ defined($rule) or confess("Subrule::pick(): $ruleName subrule cannot be found in the grammar!\n");
Branch: 1 branch
BranchTrueFalseTotal
defined $rule or confess("Subrule::pick(): $ruleName subrule cannot be found in the grammar!\n") 202 0 202
72  
73 202 my %result = $self->pickRepetitions(%args);
74 202 my $matchCnt = $result{matchCnt};
75 202 my $badOne = $result{badOne};
76  
77 202 my $val = "";
78 202 ▶ for (my $i=0; $i<$matchCnt; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $matchCnt) 612 202 814
79 612 ▶ my $matchThis = (defined($badOne) && ($i==$badOne))?0:1; # Only don't match for corrupted data
Branch: 1 branch
BranchTrueFalseTotal
defined $badOne && $i == $badOne ? : 19 593 612
Condition100%3/3
defined $badOne and $i == $badOne
!ll&&!rl&&r
5573619
MC/DC100%2/2
defined $badOne and $i == $badOne
defined $badOne $i == $badOne
Truth table100%3/3
A and B
A= defined $badOneB= $i == $badOne
ABresult
0X0
100
111
80 612 ▶ my $specifiedVals = ($matchThis && ($i==($matchCnt-1))) ? $args{vals} : { }; # Only specify rules for last capture value
Branch: 1 branch
BranchTrueFalseTotal
$matchThis && $i == $matchCnt - 1 ? : 193 419 612
Condition100%3/3
$matchThis and $i == $matchCnt - 1
!ll&&!rl&&r
19400193
MC/DC100%2/2
$matchThis and $i == $matchCnt - 1
$matchThis $i == $matchCnt - 1
Truth table100%3/3
A and B
A= $matchThisB= $i == $matchCnt - 1
ABresult
0X0
100
111
81 612 $val .= $rule->pick(%args, match=>$matchThis, vals => $specifiedVals);
82 }
83 202 ▶ if ($Debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Parse::RandGen::Subrule::Debug) 200 2 202
84 200 ▶ print("Parse::RandGen::Subrule::pick(match=>$args{match}, matchCnt=>$matchCnt, badOne=>".(defined($badOne)?$badOne:"undef")
Branch: 1 branch
BranchTrueFalseTotal
defined $badOne ? : 18 182 200
85 .") on the rule \"".$rule->dumpHeir()."\" has a value of ".$self->dumpVal($val)."\n");
86 }
87 202 return ($val);
88 }
89  
90 # Returns true (1) if this subrule contains any of the rules specified by the "vals" argument
91 202 ▶sub containsVals {
Subroutine containsVals: called CC=2 SCAR=7.1
Pod undocumented
92 202 ▶ my $self = shift or confess("%Error: Cannot call without a valid object!");
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or confess("%Error: Cannot call without a valid object!") 202 0 202
93 202 my %args = ( vals => { }, # Hash of values of various hard-coded sub-rules (by name)
94 @_ );
95 202 return $self->subrule()->containsVals(%args);
96 }
97  
98 ######################################################################
99 #### Package return
100 4 1;
101 __END__
« RandGen/Condition.pm ↑ Summary RandGen/Rule.pm »