| 1 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package Pod::Elemental::MakeSelector; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Copyright 2012 Christopher J. Madsen | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Author: Christopher J. Madsen <perl@cjmweb.net> | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # Created: 5 Jun 2012 | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 11 | # | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||||||||||||||||||||||||
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the | ||||||||||||||||||||||||||||||||||||||||||
| 15 | # GNU General Public License or the Artistic License for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # ABSTRACT: Build complex selectors as a single sub | ||||||||||||||||||||||||||||||||||||||||||
| 18 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 3 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||||||||||||||||
| 25 | # This file is part of Pod-Elemental-MakeSelector 0.12 (October 17, 2015) | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 3 | ▶ | use Sub::Exporter -setup => { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | exports => [ qw(make_selector) ], | ||||||||||||||||||||||||||||||||||||||||||
| 31 | groups => { default => [ qw(make_selector) ]}, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | #===================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 35 | # Recturn true if the first element of the arrayref is not a string | ||||||||||||||||||||||||||||||||||||||||||
| 36 | # starting with - | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | sub _has_optional_parameter | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 34 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_has_optional_parameter: called CC=3 SCAR=11.2
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 34 | my ($inputR) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 34 | ▶ | @$inputR and (ref $inputR->[0] or not $inputR->[0] =~ /^-/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
@$inputR && (ref $inputR->[0] || !($inputR->[0] =~ /^-/))
ref $inputR->[0] or not $inputR->[0] =~ /^-/
MC/DC33%1/3
@$inputR && (ref $inputR->[0] || !($inputR->[0] =~ /^-/))
@$inputR
ref $inputR->[0]
not $inputR->[0] =~ /^-/
Truth table75%3/4
A && B or not(C)
A= @$inputRB= ref $inputR->[0]C= not $inputR->[0] =~ /^-/
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | } # end _has_optional_parameter | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 46 | sub required_parameter | ||||||||||||||||||||||||||||||||||||||||||
| 47 | 25 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
required_parameter: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 25 | my ($inputR, $error_message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 25 | ▶ | croak($error_message) unless defined(my $val = shift @$inputR); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 25 | $val; | |||||||||||||||||||||||||||||||||||||||||
| 53 | } # end required_parameter | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 56 | sub add_value | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 57 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_value: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 57 | my ($valuesR, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | 57 | push @$valuesR, $value; | |||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 57 | '$val' . $#$valuesR; | |||||||||||||||||||||||||||||||||||||||||
| 63 | } # end add_value | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 66 | sub join_expressions | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 51 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
join_expressions: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 51 | my ($op, $expressionsR) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 51 | ▶ | return @$expressionsR unless @$expressionsR > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 47 | '(' . join("\n $op ", @$expressionsR) . "\n )"; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } # end join_expressions | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # Supports only string, Regexp, or arrayref of either. | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # Nested arrayrefs should work, but are not documented. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | sub smart_match | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 67 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
smart_match: called CC=6 SCAR=18.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 67 | my ($valuesR, $value, $match) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | TEST_REF: { | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 67 | my $ref = ref $match; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 67 | ▶ | if ($ref eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 10 | my $count = @$match; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 10 | ▶ | if ($count == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | return '0'; # Empty array never matches | |||||||||||||||||||||||||||||||||||||||||
| 90 | } elsif ($count == 1) { | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | $match = $match->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | redo TEST_REF; | |||||||||||||||||||||||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 8 | my $exp = join_expressions('or', | |||||||||||||||||||||||||||||||||||||||||
| 95 | [ map smart_match($valuesR, '$v', $_), @$match ] | ||||||||||||||||||||||||||||||||||||||||||
| 96 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 8 | ▶ | if ($value eq '$v') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | return $exp; | |||||||||||||||||||||||||||||||||||||||||
| 99 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 8 | return sprintf 'do { my $v = %s; %s }', $value, $exp; | |||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } elsif ($ref) { | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 17 | return "$value =~ " . add_value($valuesR, $match); | |||||||||||||||||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 40 | return "$value eq " . add_value($valuesR, $match); | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | die "Can't reach"; | |||||||||||||||||||||||||||||||||||||||||
| 111 | } # end smart_match | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 114 | sub conjunction_action | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
conjunction_action: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 9 | my ($op, $valuesR, $inputR) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | 9 | my $arrayR = shift @$inputR; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | ▶ | croak "Expected arrayref for -$op, got $arrayR" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | unless ref($arrayR) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 9 | my @expressions; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 9 | build_selector($valuesR, \@expressions, @$arrayR); | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 9 | join_expressions($op, \@expressions); | |||||||||||||||||||||||||||||||||||||||||
| 126 | } # end conjunction_action | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 129 | sub region_action | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 10 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
region_action: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 10 | my ($valuesR, $inputR, $pod) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 10 | my @expressions = type_action(qw(isa Element::Pod5::Region)); | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 10 | ▶ | push @expressions, ($pod ? '' : 'not ') . '$para->is_pod' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | if defined $pod; | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 10 | ▶ | if (_has_optional_parameter($inputR)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | push @expressions, smart_match($valuesR, '$para->format_name', | |||||||||||||||||||||||||||||||||||||||||
| 140 | shift @$inputR); | ||||||||||||||||||||||||||||||||||||||||||
| 141 | } # end if specific format(s) listed | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 10 | join_expressions(and => \@expressions); | |||||||||||||||||||||||||||||||||||||||||
| 144 | } # end region_action | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 147 | sub type_action | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 44 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
type_action: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 44 | my ($check, $class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 44 | "\$para->$check('Pod::Elemental::$class')"; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } # end type_action | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 155 | our %action = ( | ||||||||||||||||||||||||||||||||||||||||||
| 156 | 3 | ▶ | -and => sub { conjunction_action(and => @_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | 6 | ▶ | -or => sub { conjunction_action(or => @_) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | ▶ | -blank => sub { type_action(qw(isa Element::Generic::Blank)) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 7 | ▶ | -flat => sub { type_action(qw(does Flat)) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | ▶ | -node => sub { type_action(qw(does Node)) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | -code => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my ($valuesR, $inputR) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $name = add_value($valuesR, | |||||||||||||||||||||||||||||||||||||||||
| 166 | required_parameter($inputR, "-code requires a value")); | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | "$name->(\$para)"; | |||||||||||||||||||||||||||||||||||||||||
| 168 | }, #end -code | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 24 | ▶ | -command => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | 24 | my ($valuesR, $inputR) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | 24 | my @expressions = type_action(qw(does Command)); | |||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 24 | ▶ | if (_has_optional_parameter($inputR)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 22 | push @expressions, smart_match($valuesR, '$para->command', shift @$inputR); | |||||||||||||||||||||||||||||||||||||||||
| 177 | } # end if specific command(s) listed | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | 24 | join_expressions(and => \@expressions); | |||||||||||||||||||||||||||||||||||||||||
| 180 | }, #end -command | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 25 | ▶ | -content => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | 25 | my ($valuesR, $inputR) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 25 | smart_match($valuesR, '$para->content', | |||||||||||||||||||||||||||||||||||||||||
| 186 | required_parameter($inputR, "-content requires a value")); | ||||||||||||||||||||||||||||||||||||||||||
| 187 | }, #end -content | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | -region => \®ion_action, | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 4 | ▶ | -podregion => sub { region_action(@_, 1) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 2 | ▶ | -nonpodregion => sub { region_action(@_, 0) }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 3 | ); # end %action | |||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 196 | sub build_selector | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 51 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_selector: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 51 | my $valuesR = shift; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 51 | my $expR = shift; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | 51 | ▶ | while (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 78 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 78 | ▶ | my $action = $action{$type} | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | or croak "Expected selector type, got $type"; | ||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 78 | push @$expR, $action->($valuesR, \@_); | |||||||||||||||||||||||||||||||||||||||||
| 208 | } # end while more selectors | ||||||||||||||||||||||||||||||||||||||||||
| 209 | } # end build_selector | ||||||||||||||||||||||||||||||||||||||||||
| 210 | #--------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||
| 212 | # FIXME: These subs will be documented when I figure out how | ||||||||||||||||||||||||||||||||||||||||||
| 213 | # make_selector should be extended. | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | sub make_selector | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 42 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_selector: called CC=3 SCAR=11.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 42 | my @values; | |||||||||||||||||||||||||||||||||||||||||
| 219 | my @expressions; | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 42 | build_selector(\@values, \@expressions, @_); | |||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 42 | my $code = ("sub { my \$para = shift; return (\n " . | |||||||||||||||||||||||||||||||||||||||||
| 224 | join("\n and ", @expressions) . | ||||||||||||||||||||||||||||||||||||||||||
| 225 | "\n)}\n"); | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | $code = sprintf("my (%s) = \@values;\n\n%s", | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 42 | ▶ | join(', ', map { '$val' . $_ } 0 .. $#values), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | $code) | ||||||||||||||||||||||||||||||||||||||||||
| 230 | if @values; | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | #print STDERR $code; | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 42 | my ($sub, $err); | |||||||||||||||||||||||||||||||||||||||||
| 234 | { | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 42 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 236 | 42 | $sub = eval $code; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 42 | $err = $@; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 42 | ▶ | unless (ref $sub) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $lineNum = ($code =~ tr/\n//); | |||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my $fmt = '%' . length($lineNum) . 'd: '; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $lineNum = 0; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $code =~ s/^/sprintf $fmt, ++$lineNum/gem; | |||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | die "Building selector failed:\n$code$err"; | |||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||
| 249 | 42 | $sub; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } # end make_selector | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | #===================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 253 | # Package Return Value: | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | __END__ | ||||||||||||||||||||||||||||||||||||||||||