| 1 | package DBIx::MyParsePP::Rule; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 6 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 4 | 6 | @EXPORT = qw(MYPARSEPP_SHRINK_IDENTICAL MYPARSEPP_SHRINK_LEAFS MYPARSEPP_SHRINK_SINGLES MYPARSEPP_SHRINK_CHILDREN); | |||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use constant RULE_NAME => 0; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use constant MYPARSEPP_SHRINK_IDENTICAL => 1; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | ▶ | use constant MYPARSEPP_SHRINK_LEAFS => 2; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use constant MYPARSEPP_SHRINK_SINGLES => 4; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use constant MYPARSEPP_SHRINK_CHILDREN => 8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 26 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 26 | my $rule = bless (\@_, $class); | |||||||||||||||||||||||||||||||||||||||||
| 20 | 26 | return $rule; | |||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | sub getName { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | return $_[0]->[RULE_NAME]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getName: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | sub name { | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 1254 | ▶ | return $_[0]->[RULE_NAME]; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | sub children { | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 10 | ▶ | my @rule = @{$_[0]}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
children: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 10 | return @rule[1..$#rule]; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | sub getChildren { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | my @rule = @{$_[0]}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getChildren: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | return @rule[1..$#rule]; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | sub toString { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 50 | ▶ | my $rule = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toString: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 50 | ▶ | if ($#{$rule} > -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | return join('', map { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 72 | $rule->[$_]->toString(); | |||||||||||||||||||||||||||||||||||||||||
| 47 | 50 | } (1..$#{$rule}) ); | |||||||||||||||||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | sub shrink { | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 149 | ▶ | my ($parent, $flags) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shrink: called CC=14 SCAR=27.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 149 | ▶ | $flags = MYPARSEPP_SHRINK_IDENTICAL | MYPARSEPP_SHRINK_LEAFS | MYPARSEPP_SHRINK_SINGLES | MYPARSEPP_SHRINK_CHILDREN if not defined $flags; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 149 | ▶ | if (($#{$parent} == 0) && ($flags & MYPARSEPP_SHRINK_LEAFS)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
$#{$parent;} == 0 and $flags & 2
MC/DC50%1/2
$#{$parent;} == 0 and $flags & 2
$#{$parent;} == 0
$flags & 2
Truth table66%2/3
A and B
A= $#{$parent;} == 0B= $flags & 2
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 23 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 126 | ▶ | } elsif (($#{$parent} == 1) && ($flags & MYPARSEPP_SHRINK_SINGLES)) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$#{$parent;} == 1 and $flags & 4
MC/DC50%1/2
$#{$parent;} == 1 and $flags & 4
$#{$parent;} == 1
$flags & 4
Truth table66%2/3
A and B
A= $#{$parent;} == 1B= $flags & 4
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 90 | ▶ | if ($flags & MYPARSEPP_SHRINK_CHILDREN) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 80 | return $parent->[1]->shrink($flags); | |||||||||||||||||||||||||||||||||||||||||
| 63 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 10 | return $parent->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } elsif ($flags & MYPARSEPP_SHRINK_CHILDREN) { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 24 | my @new_children; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 24 | foreach my $i (1..$#{$parent}) { | |||||||||||||||||||||||||||||||||||||||||
| 70 | 67 | my $child = $parent->[$i]->shrink($flags); | |||||||||||||||||||||||||||||||||||||||||
| 71 | 67 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$flags & 1 and ref $child eq "DBIx::MyParsePP::Rule" and $child->name eq $parent->name
$flags & 1 and ref $child eq "DBIx::MyParsePP::Rule"
MC/DC0%0/3
$flags & 1 and ref $child eq "DBIx::MyParsePP::Rule" and $child->name eq $parent->name
$flags & 1
ref $child eq "DBIx::MyParsePP::Rule"
$child->name eq $parent->name
Truth table50%2/4
A and B and C
A= $flags & 1B= ref $child eq "DBIx::MyParsePP::Rule"C= $child->name eq $parent->name
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | ($flags & MYPARSEPP_SHRINK_IDENTICAL) && | ||||||||||||||||||||||||||||||||||||||||||
| 73 | (ref($child) eq 'DBIx::MyParsePP::Rule') && | ||||||||||||||||||||||||||||||||||||||||||
| 74 | ($child->name() eq $parent->name()) | ||||||||||||||||||||||||||||||||||||||||||
| 75 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | push @new_children, $child->children() if defined $child->children(); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 67 | ▶ | push @new_children, $child if defined $child; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 24 | my $new_rule = DBIx::MyParsePP::Rule->new($parent->name(), @new_children); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 24 | return $new_rule->shrink($flags & ~MYPARSEPP_SHRINK_CHILDREN); | |||||||||||||||||||||||||||||||||||||||||
| 84 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 12 | return $parent; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | sub extractInner { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 522 | ▶ | my $rule = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extractInner: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 522 | ▶ | return undef if ($#{$rule} == 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 400 | my @matches; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 400 | foreach my $i (1..$#{$rule}) { | |||||||||||||||||||||||||||||||||||||||||
| 96 | 599 | my $extract = $rule->[$i]->extract(@_); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 599 | ▶ | next if not defined $extract; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 365 | ▶ | if (ref($extract) eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 78 | push @matches, @{$extract}; | |||||||||||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 287 | push @matches, $extract; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 400 | ▶ | if ($#matches == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 59 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } elsif ($#matches == 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 258 | return $matches[0]; | |||||||||||||||||||||||||||||||||||||||||
| 109 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 83 | return \@matches; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | sub getFields { | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 1 | ▶ | return $_[0]->extract('simple_ident_q','table_ident','ident'); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getFields: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | sub fields { | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | return $_[0]->getFields(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | sub tables { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | return $_[0]->getTables(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tables: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | sub getTables { | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | my $rule = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getTables: called CC=11 SCAR=25.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | my @tables_array; | |||||||||||||||||||||||||||||||||||||||||
| 130 | my %tables_hash; | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | my $idents = $rule->extract('table_wild','table_ident','simple_ident_q'); | |||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | ▶ | $idents = [$idents] if ref($idents) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | foreach my $ident (@{$idents}) { | |||||||||||||||||||||||||||||||||||||||||
| 136 | 6 | my $shrinked_ident = $ident->shrink(); | |||||||||||||||||||||||||||||||||||||||||
| 137 | 6 | my @children = $shrinked_ident->children(); | |||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 6 | my $table; | |||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 6 | ▶ | if ($#children == -1) { # No children | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | $table = $shrinked_ident; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } elsif ($#children == 0) { # One child | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $table = $children[0]; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } elsif ($#children == 2) { | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 3 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$shrinked_ident->name eq "simple_ident_q" or $shrinked_ident->name eq "table_wild"
MC/DC100%2/2
$shrinked_ident->name eq "simple_ident_q" or $shrinked_ident->name eq "table_wild"
$shrinked_ident->name eq "simple_ident_q"
$shrinked_ident->name eq "table_wild"
Truth table100%3/3
A or B
A= $shrinked_ident->name eq "simple_ident_q"B= $shrinked_ident->name eq "table_wild"
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | ($shrinked_ident->name() eq 'simple_ident_q') || | ||||||||||||||||||||||||||||||||||||||||||
| 148 | ($shrinked_ident->name() eq 'table_wild') | ||||||||||||||||||||||||||||||||||||||||||
| 149 | ) { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 2 | $table = $children[0]; # We have "database.table" | |||||||||||||||||||||||||||||||||||||||||
| 151 | } elsif ($shrinked_ident->name() eq 'table_ident') { | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | $table = $children[2]; # We have "table.field" | |||||||||||||||||||||||||||||||||||||||||
| 153 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | print STDERR "Assertion: \$\#children == $#children but name() = ".$shrinked_ident->name()."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | } elsif ($#children == 4) { # We have "database.table.field" | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | $table = DBIx::MyParsePP::Rule->new( $ident->name(), @children[0..2] ); | |||||||||||||||||||||||||||||||||||||||||
| 159 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | print STDERR "Assertion: \$\#children == $#children\n"; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 6 | ▶ | if (not exists $tables_hash{$table->toString()}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | 6 | push @tables_array, $table; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 6 | $tables_hash{$table->toString()} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | return \@tables_array; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | sub extract { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 551 | ▶ | my $rule = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 551 | foreach my $match (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 177 | 1193 | ▶ | return $rule if ($rule->name() eq $match); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 522 | return $rule->extractInner(@_); | |||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | sub print { | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | return $_[0]->toString(); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | __END__ | ||||||||||||||||||||||||||||||||||||||||||