| 1 | package Data::Filter::Abstract::Util; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: turns data structures into sub sources | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | our @EXPORT_OK = qw(simple_sub simple_hash simple_array simple_function_hash logical_array sub_source); | |||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | our %EXPORT_TAGS = (all => [qw(simple_sub simple_hash simple_array simple_function_hash logical_array sub_source)]); | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use re qw(is_regexp regexp_pattern); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use B; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use B::Deparse; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 18 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | my $deparse = B::Deparse->new; | |||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 276 | ▶ | sub is_equality_op { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_equality_op: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 276 | my ($h) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | # return 0 unless keys($h->%*) == 1; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 276 | my $ops = { | |||||||||||||||||||||||||||||||||||||||||
| 29 | '==' => 'numeric', '!=' => 'numeric', '<' => 'numeric', '>' => 'numeric', '<=' => 'numeric', '>=' => 'numeric', # numerical comparisons | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 'eq' => 'string', 'ne' => 'string', 'lt' => 'string', 'gt' => 'string', 'le' => 'string', 'ge' => 'string', # string comparison | ||||||||||||||||||||||||||||||||||||||||||
| 31 | '=~' => 'regexp', '!~' => 'regexp', # unimplemented | ||||||||||||||||||||||||||||||||||||||||||
| 32 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 276 | ▶ | return $ops->{ (keys $h->%*)[0] } // ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$$ops{(keys %$h)[0]} // ""
MC/DC100%1/1
$$ops{(keys %$h)[0]} // ""
$$ops{(keys %$h)[0]}
Truth table100%2/2
A
A= $$ops{(keys %$h)[0]}
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 163 | ▶ | sub key_q { local $_ = shift; return /^[a-z0-9_]+$/i ? $_ : B::perlstring($_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
key_q: called CC=2 SCAR=6.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 30 | ▶ | sub var_q { B::perlstring(shift) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
var_q: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 233 | ▶ | sub simple_sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simple_sub: called CC=23 SCAR=31.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 233 | my ($k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 233 | my $r; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 233 | ▶ | if (scalar @_ == 1 && ! ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition66%2/3
scalar @_ == 1 and not ref $_[0]
MC/DC0%0/2
scalar @_ == 1 and not ref $_[0]
scalar @_ == 1
not ref $_[0]
Truth table66%2/3
A and not(B)
A= scalar @_ == 1B= not ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | return sprintf '($_->{%s})', key_q($k); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | ▶ | elsif (scalar @_ == 2 && ! ref $_[1]) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
scalar @_ == 2 and not ref $_[1]
MC/DC100%2/2
scalar @_ == 2 and not ref $_[1]
scalar @_ == 2
not ref $_[1]
Truth table100%3/3
A and not(B)
A= scalar @_ == 2B= not ref $_[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 59 | ▶ | return sprintf '(! defined $_->{%s})', key_q($k) unless defined $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | 59 | ▶ | return sprintf '($_->{%s} == %s)', key_q($k), $v if looks_like_number($v); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | 27 | return sprintf '($_->{%s} eq %s)', key_q($k), var_q($v); | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ▶ | elsif (0 == (scalar @_ % 2) && scalar @_ > 2) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
0 == scalar @_ % 2 and scalar @_ > 2
MC/DC100%2/2
0 == scalar @_ % 2 and scalar @_ > 2
0 == scalar @_ % 2
scalar @_ > 2
Truth table100%3/3
A and B
A= 0 == scalar @_ % 2B= scalar @_ > 2
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | my @args = @_; my @r; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | ▶ | while (@args) { push @r, simple_sub((shift @args), shift(@args)) } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | return sprintf "(%s)", join " && ", @r; | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 172 | ▶ | unless ($v) { $v = $k; $k = undef } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 172 | for (ref $v) { | |||||||||||||||||||||||||||||||||||||||||
| 60 | 172 | ▶ | /^Regexp$/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 33 | return sprintf '($_->{%s} =~ qr/%s/%s)', key_q($k), regexp_pattern($v); | |||||||||||||||||||||||||||||||||||||||||
| 62 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 139 | ▶ | /^HASH$/ && (is_equality_op($v)) && scalar $v->%* == 1 && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
/^HASH$/ and is_equality_op($v) and scalar %$v == 1
/^HASH$/ and is_equality_op($v)
MC/DC100%3/3
/^HASH$/ and is_equality_op($v) and scalar %$v == 1
/^HASH$/
is_equality_op($v)
scalar %$v == 1
Truth table100%4/4
A and B and C
A= /^HASH$/B= is_equality_op($v)C= scalar %$v == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 58 | return equality_op($k, $v) | |||||||||||||||||||||||||||||||||||||||||
| 65 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 81 | ▶ | /^HASH$/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 43 | ▶ | return sprintf "(%s)", join " && ", map { is_equality_op({ $_, $v->{$_} }) ? simple_sub($k => { $_, $v->{$_} }) : simple_sub($_ => $v->{$_}) } sort keys $v->%*; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 38 | ▶ | /^ARRAY$/ && ($r = (logical_array($k, $v))) && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^ARRAY$/ and $r = logical_array($k, $v)
MC/DC100%2/2
/^ARRAY$/ and $r = logical_array($k, $v)
/^ARRAY$/
$r = logical_array($k, $v)
Truth table100%3/3
A and B
A= /^ARRAY$/B= $r = logical_array($k, $v)
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 15 | return $r | |||||||||||||||||||||||||||||||||||||||||
| 71 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 23 | ▶ | /^ARRAY$/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 8 | return simple_array($k, $v) | |||||||||||||||||||||||||||||||||||||||||
| 74 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 15 | ▶ | /^SCALAR$/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | return sprintf '((looks_like_number($_->{%s})) ? ($_->{%s} == $_->{%s}) : ($_->{%s} eq $_->{%s}))', key_q($k), key_q($k), $$v, key_q($k), $$v; | |||||||||||||||||||||||||||||||||||||||||
| 77 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 9 | ▶ | /^CODE$/ && do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | # carp sprintf "WARNING: defining field \"%s\" with subref is useless\n", $k if defined $k; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 9 | return sprintf '(sub %s)', $deparse->coderef2text($v) =~ s/\s*\n\s*/ /grs, | |||||||||||||||||||||||||||||||||||||||||
| 81 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | die sprintf "%s ref is unimplemented\n", ref $v | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 3 | ▶ | sub simple_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simple_hash: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | return ((scalar keys $v->%*) > 1) ? | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 9 | sprintf "(%s)", join " && ", map { simple_sub($_, $v->{$_}) } sort keys $v->%* : | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sprintf "%s", join " && ", map { simple_sub($_, $v->{$_}) } sort keys $v->%*; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 19 | ▶ | sub simple_array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simple_array: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 19 | my ($k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | return ((scalar $v->@*) > 1) ? | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 53 | sprintf "(%s)", join " || ", map { simple_sub($k, $_) } $v->@* : | |||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sprintf "%s", join " || ", map { simple_sub($k, $_) } $v->@* ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 5 | ▶ | sub simple_function_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
simple_function_hash: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 5 | my ($k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 102 | return ((scalar keys $v->%*) > 1) ? | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 10 | sprintf "(%s)", join " && ", map { simple_sub($k, { $_, $v->{$_} }) } sort keys $v->%* : | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sprintf "%s", join " && ", map { simple_sub($k, { $_, $v->{$_} }) } sort keys $v->%* ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 26 | ▶ | sub logical_array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
logical_array: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 26 | my ($k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 26 | my @v = $v->@*; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 26 | my $ops = { '-and' => " && ", '-or' => " || " }; | |||||||||||||||||||||||||||||||||||||||||
| 111 | 26 | ▶ | return unless $ops->{$v[0]}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 18 | my $l = $ops->{(shift @v)}; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 18 | ▶ | die sprintf "Using array as arg with logical op is not permitted\n", $k if ref $v[0] eq "ARRAY"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 18 | return sprintf "(%s)", join $l, map { simple_sub($k, $_) } @v; | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | # ------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 118 | # Equality ops | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # ------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 4 | ▶ | sub equality_op_string { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equality_op_string: called CC=6 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 4 | my ($k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | my $values = (values $v->%*)[0]; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 4 | ▶ | if (ref($values) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 1 | return simple_array($k, (values $v->%*)) | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | elsif (!defined ((values $v->%*)[0]) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my ($o, $d) = $v->%*; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | croak "Use of %s and undef in filter is not allowed", $o unless $o eq 'ne' or $o eq 'eq'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$o eq "ne" or $o eq "eq"
MC/DC0%0/2
$o eq "ne" or $o eq "eq"
$o eq "ne"
$o eq "eq"
Truth table0%0/3
A or B
A= $o eq "ne"B= $o eq "eq"
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | return sprintf '(%sdefined $_->{%s})', ($o eq 'ne' ? '' : '!'), key_q($k); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 3 | return sprintf "(%s)", join " && ", map { sprintf '($_->{%s} %s %s)', key_q($k), $_, var_q($v->{$_}) } keys $v->%* | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 45 | ▶ | sub equality_op_numeric { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equality_op_numeric: called CC=6 SCAR=27.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 45 | my ($k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 45 | my $values = (values $v->%*)[0]; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 45 | ▶ | if (ref($values) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | return simple_array($k, (values $v->%*)) | |||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||
| 143 | elsif (!defined ((values $v->%*)[0]) ) { | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my ($o, $d) = $v->%*; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | croak "Use of %s and undef in filter is not allowed", $o unless $o eq '!=' or $o eq '=='; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$o eq "!=" or $o eq "=="
MC/DC0%0/2
$o eq "!=" or $o eq "=="
$o eq "!="
$o eq "=="
Truth table0%0/3
A or B
A= $o eq "!="B= $o eq "=="
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | return sprintf "(%s)", sprintf '(%sdefined $_->{%s})', ($o eq '!=' ? '' : '!'), key_q($k); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||
| 148 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 45 | return sprintf "(%s)", join " && ", map { sprintf '($_->{%s} %s %s)', key_q($k), $_, $v->{$_} } keys $v->%* | |||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 9 | ▶ | sub equality_op_regex { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equality_op_regex: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 9 | my ($k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 9 | my $values = (values $v->%*)[0]; | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 9 | ▶ | if (ref($values) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 4 | ▶ | return simple_array($k, [ map { ref $_ eq "Regexp" ? $_ : qr/$_/ } $values->@* ]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||
| 160 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 161 | return join " && ", map { | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 5 | ▶ | my $re = ref ($v->{$_}) eq "Regexp" ? $v->{$_} : qr/$v->{$_}/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | sprintf '($_->{%s} %s qr/%s/%s)', key_q($k), $_, regexp_pattern($re)} keys $v->%*; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 58 | ▶ | sub equality_op { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
equality_op: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 58 | my ($k, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 58 | my $values = (values $v->%*)[0]; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 58 | ▶ | if (is_equality_op($v) eq 'string') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 4 | return equality_op_string($k, $v); | |||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | elsif (is_equality_op($v) eq 'numeric') { | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 45 | return equality_op_numeric($k, $v) | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | elsif (is_equality_op($v) eq 'regexp') { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 9 | return equality_op_regex($k, $v) | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | croak "Unhandled operator %s", keys $v->%*; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | Data::Filter::Abstract::Util - DSL for generating Perl filter expressions from data structures | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | use Data::Filter::Abstract::Util qw(:all); | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | my $expr = simple_sub(foo => "bar"); | ||||||||||||||||||||||||||||||||||||||||||
| 197 | # => '($_->{foo} eq "bar")' | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | my $code = eval "sub { $expr }"; | ||||||||||||||||||||||||||||||||||||||||||
| 200 | $code->({ foo => "bar" }); # true | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | This module implements a small domain-specific language (DSL) for describing | ||||||||||||||||||||||||||||||||||||||||||
| 205 | boolean filters as Perl data structures. The DSL is compiled into Perl | ||||||||||||||||||||||||||||||||||||||||||
| 206 | expressions (as strings) which operate on C<$_>, assumed to be a hash reference. | ||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | The resulting expressions are intended to be embedded into C<sub { ... }> | ||||||||||||||||||||||||||||||||||||||||||
| 209 | blocks and evaluated. | ||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | The test suite defines the DSL behavior and serves as its authoritative | ||||||||||||||||||||||||||||||||||||||||||
| 212 | specification. | ||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | =head1 GENERAL SEMANTICS | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||
| 220 | All generated expressions assume C<$_> is a hash reference. | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | Field access is performed as C<$_->{field}>. | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | Hashes represent logical AND. | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | Arrays represent logical OR, unless explicitly overridden by logical operators. | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | =item * | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | Generated expressions are syntactically valid Perl code suitable for C<eval>. | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | =head1 BASIC FILTER FORMS | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | =head2 Scalar equality | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | simple_sub(foo => "bar") | ||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | Generates a string equality comparison: | ||||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||||
| 248 | ($_->{foo} eq "bar") | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | If the value looks like a number, numeric comparison is used: | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | simple_sub(foo => 1) | ||||||||||||||||||||||||||||||||||||||||||
| 253 | # ($_->{foo} == 1) | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | =head2 Regular expressions | ||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||
| 257 | simple_sub(foo => qr/12/) | ||||||||||||||||||||||||||||||||||||||||||
| 258 | simple_sub(foo => qr/[a-z]/i) | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | Generates regex match expressions: | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | ($_->{foo} =~ qr/12/) | ||||||||||||||||||||||||||||||||||||||||||
| 263 | ($_->{foo} =~ qr/[a-z]/i) | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | =head2 Hash form (implicit AND) | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | simple_sub({ bar => 1, baz => "wq", boo => qr/12/ }) | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | Equivalent to: | ||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | ($_->{bar} == 1) | ||||||||||||||||||||||||||||||||||||||||||
| 272 | && ($_->{baz} eq "wq") | ||||||||||||||||||||||||||||||||||||||||||
| 273 | && ($_->{boo} =~ qr/12/) | ||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||
| 275 | C<simple_hash> behaves identically. | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | =head1 ARRAY FORMS | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | =head2 Simple OR array | ||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | simple_sub(foo => [ 1, "wq", qr/12/ ]) | ||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||
| 283 | Generates a logical OR over the values: | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | ($_->{foo} == 1) | ||||||||||||||||||||||||||||||||||||||||||
| 286 | || ($_->{foo} eq "wq") | ||||||||||||||||||||||||||||||||||||||||||
| 287 | || ($_->{foo} =~ qr/12/) | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | =head2 Arrays of operator expressions | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | simple_array(foo => [ { '==', 2 }, { '>', 5 } ]) | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | Generates: | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | ($_->{foo} == 2) || ($_->{foo} > 5) | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | =head1 LOGICAL ARRAYS | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | Arrays may begin with a logical operator to control how elements are combined. | ||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | =head2 AND logic | ||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | simple_sub(foo => [ -and => { '==', 2 }, { '>=', 5 } ]) | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | Generates: | ||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | ($_->{foo} == 2) && ($_->{foo} >= 5) | ||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||
| 309 | =head2 OR logic | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | simple_sub(foo => [ -or => { '==', 2 }, { '>=', 5 } ]) | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | Generates: | ||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||
| 315 | ($_->{foo} == 2) || ($_->{foo} >= 5) | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | =head1 OPERATOR HASHES (FUNCTION HASHES) | ||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | A field value may be a hash mapping operators to values. | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | simple_sub(foo => { '>' => 12, '<' => 23 }) | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | Generates: | ||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | ($_->{foo} < 23) && ($_->{foo} > 12) | ||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | The order of operators is not significant. | ||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | =head2 Supported operators (as tested) | ||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||
| 333 | =item * String operators | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | eq ne lt le gt ge | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | =item * Numeric operators | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | == != < <= > >= | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | =item * Regex operators | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | =~ !~ | ||||||||||||||||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||||||||||||||
| 345 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | =head1 OPERATORS WITH ARRAY VALUES | ||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | =head2 Equality with array | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | simple_sub(status => { eq => [ 'assigned', 'in-progress', 'pending' ] }) | ||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | Generates an OR expression: | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | ($_->{status} eq "assigned") | ||||||||||||||||||||||||||||||||||||||||||
| 356 | || ($_->{status} eq "in-progress") | ||||||||||||||||||||||||||||||||||||||||||
| 357 | || ($_->{status} eq "pending") | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | Equivalent logic may also be expressed via a logical array: | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | simple_sub(status => [ | ||||||||||||||||||||||||||||||||||||||||||
| 362 | -or => | ||||||||||||||||||||||||||||||||||||||||||
| 363 | { eq => 'assigned' }, | ||||||||||||||||||||||||||||||||||||||||||
| 364 | { eq => 'in-progress' }, | ||||||||||||||||||||||||||||||||||||||||||
| 365 | { eq => 'pending' }, | ||||||||||||||||||||||||||||||||||||||||||
| 366 | ]) | ||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||
| 368 | =head2 Regex operators with arrays | ||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | simple_sub(foo => { '=~' => [ qr/12/, qr/23/i ] }) | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | Generates: | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | ($_->{foo} =~ qr/12/) | ||||||||||||||||||||||||||||||||||||||||||
| 375 | || ($_->{foo} =~ qr/23/i) | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | Non-regex values are coerced to regexes: | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | simple_sub(foo => { '=~' => [ "12", qr/23/i ] }) | ||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | =head1 UNDEF HANDLING | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | simple_sub(user => undef) | ||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | Generates: | ||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | (! defined $_->{user}) | ||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | Operator hashes may also compare against undef, though some combinations are | ||||||||||||||||||||||||||||||||||||||||||
| 390 | known to be problematic (see tests marked as failing). | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | =head1 FIELD-TO-FIELD COMPARISON (SCALAR REF) | ||||||||||||||||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||||||||||||||||
| 394 | If the value is a scalar reference, it is interpreted as another field name. | ||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | simple_sub(foo => \"bar") | ||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||
| 398 | Generates a dynamic comparison: | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | ( (looks_like_number($_->{foo})) | ||||||||||||||||||||||||||||||||||||||||||
| 401 | ? ($_->{foo} == $_->{bar}) | ||||||||||||||||||||||||||||||||||||||||||
| 402 | : ($_->{foo} eq $_->{bar}) | ||||||||||||||||||||||||||||||||||||||||||
| 403 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 404 | |||||||||||||||||||||||||||||||||||||||||||
| 405 | This form may also appear inside logical arrays. | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | =head1 CODE REFERENCES | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | A code reference may be supplied as a filter. | ||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||
| 411 | simple_sub(sub { $_->{foo}->{bar} > 5 }) | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | or | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | simple_sub(foo => sub { $_->{foo}->{bar} > 5 }) | ||||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | The code reference is deparsed and embedded verbatim: | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | (sub { use strict; $_->{'foo'}{'bar'} > 5; }) | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | The field name is ignored when a code reference is supplied. | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | =head1 MIXED COMPLEX EXPRESSIONS | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | Arrays may contain mixed value types: | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | simple_sub(foo => [ | ||||||||||||||||||||||||||||||||||||||||||
| 428 | 1, | ||||||||||||||||||||||||||||||||||||||||||
| 429 | "wq", | ||||||||||||||||||||||||||||||||||||||||||
| 430 | qr/12/, | ||||||||||||||||||||||||||||||||||||||||||
| 431 | sub { shift()->{foo}->{bar} > 5 } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | ]) | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | Generates a logical OR over all components. | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | L<Data::Filter::Abstract>, L<SQL::Abstract> | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | =cut | ||||||||||||||||||||||||||||||||||||||||||