/usr/share/perl5/RDF/Query/Plan/Filter.pm is in librdf-query-perl 2.918-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 | # RDF::Query::Plan::Filter
# -----------------------------------------------------------------------------
=head1 NAME
RDF::Query::Plan::Filter - Executable query plan for Filters.
=head1 VERSION
This document describes RDF::Query::Plan::Filter version 2.918.
=head1 METHODS
Beyond the methods documented below, this class inherits methods from the
L<RDF::Query::Plan> class.
=over 4
=cut
package RDF::Query::Plan::Filter;
use strict;
use warnings;
use base qw(RDF::Query::Plan);
use RDF::Query::Error qw(:try);
use Scalar::Util qw(blessed);
######################################################################
our ($VERSION);
BEGIN {
$VERSION = '2.918';
}
######################################################################
=item C<< new ( $plan, $expr, $active_graph ) >>
=cut
sub new {
my $class = shift;
my $expr = shift;
my $plan = shift;
my $graph = shift;
my $self = $class->SUPER::new( $expr, $plan, $graph );
$self->[0]{referenced_variables} = [ $plan->referenced_variables ];
return $self;
}
=item C<< execute ( $execution_context ) >>
=cut
sub execute ($) {
my $self = shift;
my $context = shift;
$self->[0]{delegate} = $context->delegate;
if ($self->state == $self->OPEN) {
throw RDF::Query::Error::ExecutionError -text => "FILTER plan can't be executed while already open";
}
my $plan = $self->[2];
$plan->execute( $context );
my $l = Log::Log4perl->get_logger("rdf.query.plan.filter");
if ($plan->state == $self->OPEN) {
$self->state( $self->OPEN );
my $expr = $self->[1];
my $bool = RDF::Query::Node::Resource->new( "sparql:ebv" );
my $filter = RDF::Query::Expression::Function->new( $bool, $expr );
if ($l->is_trace) {
$l->trace("filter constructed for " . $expr->sse({}, ''));
}
my $query = $context->query;
my $bridge = $context->model;
$self->[0]{filter} = sub {
my $row = shift;
my $bool = 0;
try {
my $qok = ref($query);
local($query->{_query_row_cache}) = {};
unless ($qok) {
# $query may not be defined, but the local() call will autovivify it into a HASH.
# later on, if it's a ref, somebody's going to try to call a method on it, so
# undef it if it wasn't defined before the local() call.
$query = undef;
}
my $value = $filter->evaluate( $query, $row, $context, $self->active_graph );
$bool = ($value->literal_value eq 'true') ? 1 : 0;
} catch RDF::Query::Error with {
my $e = shift;
no warnings 'uninitialized';
$l->debug( 'exception thrown during filter evaluation: ' . $e->text );
} otherwise {
$l->debug( 'error during filter evaluation: ' . $@);
};
return $bool;
};
} else {
warn "could not execute plan in filter";
}
$self;
}
=item C<< next >>
=cut
sub next {
my $self = shift;
unless ($self->state == $self->OPEN) {
throw RDF::Query::Error::ExecutionError -text => "next() cannot be called on an un-open FILTER";
}
my $plan = $self->[2];
my $filter = $self->[0]{filter};
my $l = Log::Log4perl->get_logger("rdf.query.plan.filter");
while (1) {
my $row = $plan->next;
unless (defined($row)) {
$l->debug("no remaining rows in filter");
return;
}
if ($l->is_trace) {
$l->trace("filter processing bindings $row");
}
if ($filter->( $row )) {
$l->trace( "- filter returned true on row" );
if (my $d = $self->delegate) {
$d->log_result( $self, $row );
}
return $row;
} else {
$l->trace( "- filter returned false on row" );
}
}
}
=item C<< close >>
=cut
sub close {
my $self = shift;
unless ($self->state == $self->OPEN) {
throw RDF::Query::Error::ExecutionError -text => "close() cannot be called on an un-open FILTER";
}
delete $self->[0]{filter};
if (blessed($self->pattern)) {
$self->pattern->close();
}
$self->SUPER::close();
}
=item C<< pattern >>
Returns the query plan that will be used to produce the data to be filtered.
=cut
sub pattern {
my $self = shift;
return $self->[2];
}
=item C<< active_graph >>
Returns the active graph.
=cut
sub active_graph {
my $self = shift;
return $self->[3];
}
=item C<< distinct >>
Returns true if the pattern is guaranteed to return distinct results.
=cut
sub distinct {
my $self = shift;
return $self->pattern->distinct;
}
=item C<< ordered >>
Returns true if the pattern is guaranteed to return ordered results.
=cut
sub ordered {
my $self = shift;
return $self->pattern->ordered;
}
=item C<< plan_node_name >>
Returns the string name of this plan node, suitable for use in serialization.
=cut
sub plan_node_name {
return 'filter';
}
=item C<< plan_prototype >>
Returns a list of scalar identifiers for the type of the content (children)
nodes of this plan node. See L<RDF::Query::Plan> for a list of the allowable
identifiers.
=cut
sub plan_prototype {
my $self = shift;
return qw(E P);
}
=item C<< plan_node_data >>
Returns the data for this plan node that corresponds to the values described by
the signature returned by C<< plan_prototype >>.
=cut
sub plan_node_data {
my $self = shift;
my $expr = $self->[1];
return ($expr, $self->pattern);
}
1;
__END__
=back
=head1 AUTHOR
Gregory Todd Williams <gwilliams@cpan.org>
=cut
|