| 1 | # $Revision: #3 $$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::Rule; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 Data::Dumper; # FIX - debug only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 4 | ▶ | use vars qw($Debug); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | #### Creators | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 9 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 9 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 9 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | _name => undef, # Name of the rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | _grammar => undef, # Reference to the parent Grammar object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | _productions => [ ], # Productions for the rule | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | ▶ | bless $self, ref($class)||$class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | $self->{_name} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | !defined($self->{_name}) or ($self->{_name} =~ /^[a-z_]\w*$/i) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | ▶ | or confess("The specified rule name must be exclusively alphanumeric characters (", $self->{_name}, ")!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $self->{"_name"} or $self->{"_name"} =~ /^[a-z_]\w*$/i
MC/DC0%0/2
not defined $self->{"_name"} or $self->{"_name"} =~ /^[a-z_]\w*$/i
not defined $self->{"_name"}
$self->{"_name"} =~ /^[a-z_]\w*$/i
Truth table66%2/3
not(A) or B
A= not defined $self->{"_name"}B= $self->{"_name"} =~ /^[a-z_]\w*$/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | return($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | #### Methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=6 SCAR=19.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | my $self = shift or confess("%Error: Cannot call without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 1 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 1 | my $prodType = "Parse::RandGen::Production"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | my $numArgs = $#args + 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | ▶ | ($numArgs) or confess("%Error: Rule::set() called with no arguments!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 1 | ▶ | ($numArgs % 2) and confess("%Error: Rule::set() called with an odd number of arguments ($numArgs); arguments must be in named pairs!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | while ($#args >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 1 | my ($arg, $val) = (shift(@args), shift(@args)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | if ($arg eq "prod") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | $self->addProd($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Unknown arguments become data members | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $self->{$arg} = $val; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 11 | ▶ | sub addProd { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
addProd: called CC=7 SCAR=19.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 11 | ▶ | my $self = shift or confess("%Error: Cannot call without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 11 | my @args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 11 | my $prodType = "Parse::RandGen::Production"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 11 | foreach my $arg (@args) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 11 | my $prod; # Production object | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 11 | my $type = ref($arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 11 | ▶ | if ($type && UNIVERSAL::isa($arg, $prodType)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$type and UNIVERSAL::isa($arg, $prodType)
MC/DC50%1/2
$type and UNIVERSAL::isa($arg, $prodType)
$type
UNIVERSAL::isa($arg, $prodType)
Truth table66%2/3
A and B
A= $typeB= UNIVERSAL::isa($arg, $prodType)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 10 | $prod = $arg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } elsif ($type eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # [ 'http://' host path(?) ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 1 | $prod = Parse::RandGen::Production->new(@$arg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | confess("%Error: Passed a $type argument instead of a $prodType or ARRAY reference argument!"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | ▶ | defined($prod->{_rule}) and confess("%Error: Adding a Production that already belongs to another Rule!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 10 | $prod->{_rule} = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 10 | push @{$self->{_productions}}, $prod; # Add the production to the end of the _productions list | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 10 | $prod->{_number} = $#{$self->{_productions}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | ▶ | my $self = shift or confess("%Error: Cannot call without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return "%Error: Production has no Grammar object!" unless $self->grammar(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $grammarName = $self->grammar()->name(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $err = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | foreach my $prod (@{$self->{_productions}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $err .= $prod->check(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return $err; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub dump { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | my $self = shift or confess("%Error: Cannot call without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $output = $self->name() . ":\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $firstProd = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | foreach my $prod (@{$self->{_productions}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | if ($firstProd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $output .= "\t\t "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $firstProd = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | $output .= "\t\t| "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $output .= $prod->dump() . "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $output .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 200 | ▶ | sub dumpHeir { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dumpHeir: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 200 | ▶ | my $self = shift or confess("%Error: Cannot call without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 200 | ▶ | my $name = defined($self->name()) ? ($self->name() . ":") : ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 200 | my $output = "($name "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 200 | my $firstProd = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 200 | foreach my $prod (@{$self->{_productions}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 400 | ▶ | if ($firstProd) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 200 | $firstProd = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 200 | $output .= " | "; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 400 | $output .= $prod->dumpHeir(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 200 | $output .= " )"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 814 | ▶ | sub pick { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pick: called CC=8 SCAR=22.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 814 | ▶ | my $self = shift or confess("%Error: Cannot call without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 814 | my %args = ( match=>1, # Default is to pick matching data | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | vals => { }, # Hash of values of various hard-coded sub-rules (by name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | # Return explicitly specified value (if specified by name or reference to $self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 814 | ▶ | return $args{vals}{$self->name()} if (defined($self->name()) && defined($args{vals}{$self->name()})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->name and defined $args{"vals"}{$self->name}
MC/DC0%0/2
defined $self->name and defined $args{"vals"}{$self->name}
defined $self->name
defined $args{"vals"}{$self->name}
Truth table33%1/3
A and B
A= defined $self->nameB= defined $args{"vals"}{$self->name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 814 | ▶ | return $args{vals}{$self} if defined($args{vals}{$self}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 814 | my @prods; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 814 | foreach my $prod ($self->productions()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1426 | ▶ | push(@prods, $prod) if $prod->containsVals(%args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 814 | ▶ | @prods = $self->productions() unless(@prods); # If {vals} does not specify any production of this rule, pick from all productions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 814 | my $prodNum = int(rand($#prods+1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 814 | return( $prods[$prodNum]->pick(%args) ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # Returns true (1) if this rule is or has any explicitly specified values in the "vals" argument | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 202 | ▶ | sub containsVals { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
containsVals: called CC=7 SCAR=21.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 202 | ▶ | my $self = shift or confess("%Error: Cannot call without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 202 | my %args = ( vals => { }, # Hash of values of various hard-coded sub-rules (by name) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | @_ ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # Return true if this rule is explicitly specified (if specified by name or reference to $self) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 202 | ▶ | return 1 if (defined($self->name()) && defined($args{vals}{$self->name()})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->name and defined $args{"vals"}{$self->name}
MC/DC0%0/2
defined $self->name and defined $args{"vals"}{$self->name}
defined $self->name
defined $args{"vals"}{$self->name}
Truth table33%1/3
A and B
A= defined $self->nameB= defined $args{"vals"}{$self->name}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 202 | ▶ | return 1 if defined($args{vals}{$self}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 202 | foreach my $prod ($self->productions()) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 404 | ▶ | return 1 if $prod->containsVals(%args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 202 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | #### Accessors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1218 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1218 | ▶ | my $self = shift or confess("%Error: Cannot call name() without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1218 | return $self->{_name}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | ▶ | sub grammar { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
grammar: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | ▶ | my $self = shift or confess("%Error: Cannot call grammar() without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 1 | return $self->{_grammar}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1830 | ▶ | sub productions { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
productions: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 1830 | ▶ | my $self = shift or confess("%Error: Cannot call productions() without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1830 | return (@{$self->{_productions}}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | sub production { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
production: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | my $self = shift or confess("%Error: Cannot call productions() without a valid object!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | my $prodIdent = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | defined($prodIdent) or confess("%Error: Must specify either the name or the number of the production to be found!"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $isNumber = ($prodIdent !~ m/[^\d]/); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | foreach my $prod (@{$self->{_productions}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | if ( ($isNumber && ($prod->{_number} == $prodIdent)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$isNumber and $prod->{"_number"} == $prodIdent or defined $prod->{"_name"} and $prod->{"_name"} eq $prodIdent
$isNumber and $prod->{"_number"} == $prodIdent
defined $prod->{"_name"} and $prod->{"_name"} eq $prodIdent
MC/DC0%0/4
$isNumber and $prod->{"_number"} == $prodIdent or defined $prod->{"_name"} and $prod->{"_name"} eq $prodIdent
$isNumber
$prod->{"_number"} == $prodIdent
defined $prod->{"_name"}
$prod->{"_name"} eq $prodIdent
Truth table0%0/7
A and B or C and D
A= $isNumberB= $prod->{"_number"} == $prodIdentC= defined $prod->{"_name"}D= $prod->{"_name"} eq $prodIdent
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | || (defined($prod->{_name}) && ($prod->{_name} eq $prodIdent)) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | return $prod; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | return undef; # Not found | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ###################################################################### | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | #### Package return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||