| 1 | # RDF::Query::Algebra::Service | ||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||
| 3 | |||||||||||||
| 4 | =head1 NAME | ||||||||||||
| 5 | |||||||||||||
| 6 | RDF::Query::Algebra::Service - Algebra class for SERVICE (federation) patterns | ||||||||||||
| 7 | |||||||||||||
| 8 | =head1 VERSION | ||||||||||||
| 9 | |||||||||||||
| 10 | This document describes RDF::Query::Algebra::Service version 2.919. | ||||||||||||
| 11 | |||||||||||||
| 12 | =cut | ||||||||||||
| 13 | |||||||||||||
| 14 | package RDF::Query::Algebra::Service; | ||||||||||||
| 15 | |||||||||||||
| 16 | 36 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | 36 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 18 | 36 | ▶ | use base qw(RDF::Query::Algebra); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | |||||||||||||
| 20 | 36 | ▶ | use Log::Log4perl; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 21 | 36 | ▶ | use URI::Escape; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 22 | 36 | ▶ | use MIME::Base64; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | 36 | ▶ | use Data::Dumper; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | 36 | ▶ | use RDF::Query::Error; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 25 | 36 | ▶ | use Carp qw(carp croak confess); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 26 | 36 | ▶ | use Scalar::Util qw(blessed reftype); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 27 | 36 | ▶ | use Storable qw(store_fd fd_retrieve); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 28 | 36 | ▶ | use RDF::Trine::Iterator qw(sgrep smap swatch); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 29 | |||||||||||||
| 30 | ###################################################################### | ||||||||||||
| 31 | |||||||||||||
| 32 | 36 | our ($VERSION, $BLOOM_FILTER_ERROR_RATE); | |||||||||||
| 33 | 36 | ▶ | BEGIN { | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 34 | 36 | $BLOOM_FILTER_ERROR_RATE = 0.1; | |||||||||||
| 35 | 36 | $VERSION = '2.919'; | |||||||||||
| 36 | } | ||||||||||||
| 37 | |||||||||||||
| 38 | ###################################################################### | ||||||||||||
| 39 | |||||||||||||
| 40 | =head1 METHODS | ||||||||||||
| 41 | |||||||||||||
| 42 | Beyond the methods documented below, this class inherits methods from the | ||||||||||||
| 43 | L<RDF::Query::Algebra> class. | ||||||||||||
| 44 | |||||||||||||
| 45 | =over 4 | ||||||||||||
| 46 | |||||||||||||
| 47 | =cut | ||||||||||||
| 48 | |||||||||||||
| 49 | =item C<new ( $endpoint, $pattern, $silent )> | ||||||||||||
| 50 | |||||||||||||
| 51 | Returns a new Service structure. | ||||||||||||
| 52 | |||||||||||||
| 53 | =cut | ||||||||||||
| 54 | |||||||||||||
| 55 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 56 | 0 | my $class = shift; | |||||||||||
| 57 | 0 | my $endpoint = shift; | |||||||||||
| 58 | 0 | my $pattern = shift; | |||||||||||
| 59 | 0 | ▶ | my $silent = shift || 0; | ||||||||||
|
Condition0%0/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 60 | 0 | my $ggp = shift; | |||||||||||
| 61 | 0 | return bless( [ 'SERVICE', $endpoint, $pattern, $silent, $ggp ], $class ); | |||||||||||
| 62 | } | ||||||||||||
| 63 | |||||||||||||
| 64 | =item C<< construct_args >> | ||||||||||||
| 65 | |||||||||||||
| 66 | Returns a list of arguments that, passed to this class' constructor, | ||||||||||||
| 67 | will produce a clone of this algebra pattern. | ||||||||||||
| 68 | |||||||||||||
| 69 | =cut | ||||||||||||
| 70 | |||||||||||||
| 71 | 0 | ▶ | sub construct_args { | ||||||||||
|
Subroutine
construct_args: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 72 | 0 | my $self = shift; | |||||||||||
| 73 | 0 | return ($self->endpoint, $self->pattern, $self->silent, $self->lhs); | |||||||||||
| 74 | } | ||||||||||||
| 75 | |||||||||||||
| 76 | =item C<< endpoint >> | ||||||||||||
| 77 | |||||||||||||
| 78 | Returns the endpoint resource of the named graph expression. | ||||||||||||
| 79 | |||||||||||||
| 80 | =cut | ||||||||||||
| 81 | |||||||||||||
| 82 | 0 | ▶ | sub endpoint { | ||||||||||
|
Subroutine
endpoint: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 83 | 0 | my $self = shift; | |||||||||||
| 84 | 0 | ▶ | if (@_) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | 0 | my $endpoint = shift; | |||||||||||
| 86 | 0 | $self->[1] = $endpoint; | |||||||||||
| 87 | } | ||||||||||||
| 88 | 0 | my $endpoint = $self->[1]; | |||||||||||
| 89 | 0 | return $endpoint; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | =item C<< pattern >> | ||||||||||||
| 93 | |||||||||||||
| 94 | Returns the graph pattern of the named graph expression. | ||||||||||||
| 95 | |||||||||||||
| 96 | =cut | ||||||||||||
| 97 | |||||||||||||
| 98 | 0 | ▶ | sub pattern { | ||||||||||
|
Subroutine
pattern: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||
| 100 | 0 | ▶ | if (@_) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 101 | 0 | my $pattern = shift; | |||||||||||
| 102 | 0 | $self->[2] = $pattern; | |||||||||||
| 103 | } | ||||||||||||
| 104 | 0 | return $self->[2]; | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | =item C<< silent >> | ||||||||||||
| 108 | |||||||||||||
| 109 | Returns true if the service operation is to ignore errors during execution. | ||||||||||||
| 110 | |||||||||||||
| 111 | =cut | ||||||||||||
| 112 | |||||||||||||
| 113 | 0 | ▶ | sub silent { | ||||||||||
|
Subroutine
silent: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 114 | 0 | my $self = shift; | |||||||||||
| 115 | 0 | return $self->[3]; | |||||||||||
| 116 | } | ||||||||||||
| 117 | |||||||||||||
| 118 | =item C<< lhs >> | ||||||||||||
| 119 | |||||||||||||
| 120 | If the SERVCE operation uses a variable endpoint, then it is considered a binary | ||||||||||||
| 121 | operator, executing the left-hand-side pattern first, and using results from it | ||||||||||||
| 122 | to bind endpoint URL values to use in SERVICE evaluation. | ||||||||||||
| 123 | |||||||||||||
| 124 | =cut | ||||||||||||
| 125 | |||||||||||||
| 126 | 0 | ▶ | sub lhs { | ||||||||||
|
Subroutine
lhs: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||
| 128 | 0 | return $self->[4]; | |||||||||||
| 129 | } | ||||||||||||
| 130 | |||||||||||||
| 131 | =item C<< sse >> | ||||||||||||
| 132 | |||||||||||||
| 133 | Returns the SSE string for this algebra expression. | ||||||||||||
| 134 | |||||||||||||
| 135 | =cut | ||||||||||||
| 136 | |||||||||||||
| 137 | 0 | ▶ | sub sse { | ||||||||||
|
Subroutine
sse: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 138 | 0 | my $self = shift; | |||||||||||
| 139 | 0 | my $context = shift; | |||||||||||
| 140 | 0 | ▶ | my $prefix = shift || ''; | ||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 141 | 0 | my $indent = $context->{indent}; | |||||||||||
| 142 | |||||||||||||
| 143 | 0 | ▶ | if (my $ggp = $self->lhs) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 144 | 0 | return sprintf( | |||||||||||
| 145 | "(service\n${prefix}${indent}%s\n${prefix}${indent}%s\n${prefix}${indent}%s)", | ||||||||||||
| 146 | $self->lhs->sse( $context, "${prefix}${indent}" ), | ||||||||||||
| 147 | $self->endpoint->sse( $context, "${prefix}${indent}" ), | ||||||||||||
| 148 | $self->pattern->sse( $context, "${prefix}${indent}" ) | ||||||||||||
| 149 | ); | ||||||||||||
| 150 | } else { | ||||||||||||
| 151 | 0 | return sprintf( | |||||||||||
| 152 | "(service\n${prefix}${indent}%s\n${prefix}${indent}%s)", | ||||||||||||
| 153 | $self->endpoint->sse( $context, "${prefix}${indent}" ), | ||||||||||||
| 154 | $self->pattern->sse( $context, "${prefix}${indent}" ) | ||||||||||||
| 155 | ); | ||||||||||||
| 156 | } | ||||||||||||
| 157 | } | ||||||||||||
| 158 | |||||||||||||
| 159 | =item C<< as_sparql >> | ||||||||||||
| 160 | |||||||||||||
| 161 | Returns the SPARQL string for this algebra expression. | ||||||||||||
| 162 | |||||||||||||
| 163 | =cut | ||||||||||||
| 164 | |||||||||||||
| 165 | 0 | ▶ | sub as_sparql { | ||||||||||
|
Subroutine
as_sparql: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 166 | 0 | my $self = shift; | |||||||||||
| 167 | 0 | my $context = shift; | |||||||||||
| 168 | 0 | my $indent = shift; | |||||||||||
| 169 | 0 | ▶ | my $op = ($self->silent) ? 'SERVICE SILENT' : 'SERVICE'; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 170 | 0 | ▶ | if (my $ggp = $self->lhs) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 171 | 0 | local($context->{skip_filter}) = 0; | |||||||||||
| 172 | 0 | my $string = sprintf( | |||||||||||
| 173 | "%s\n${indent}%s %s %s", | ||||||||||||
| 174 | $ggp->as_sparql( $context, $indent ), | ||||||||||||
| 175 | $op, | ||||||||||||
| 176 | $self->endpoint->as_sparql( $context, $indent ), | ||||||||||||
| 177 | $self->pattern->as_sparql( { %$context, force_ggp_braces => 1 }, $indent ), | ||||||||||||
| 178 | ); | ||||||||||||
| 179 | 0 | return $string; | |||||||||||
| 180 | } else { | ||||||||||||
| 181 | 0 | my $string = sprintf( | |||||||||||
| 182 | "%s %s %s", | ||||||||||||
| 183 | $op, | ||||||||||||
| 184 | $self->endpoint->as_sparql( $context, $indent ), | ||||||||||||
| 185 | $self->pattern->as_sparql( { %$context, force_ggp_braces => 1 }, $indent ), | ||||||||||||
| 186 | ); | ||||||||||||
| 187 | 0 | return $string; | |||||||||||
| 188 | } | ||||||||||||
| 189 | } | ||||||||||||
| 190 | |||||||||||||
| 191 | =item C<< as_hash >> | ||||||||||||
| 192 | |||||||||||||
| 193 | Returns the query as a nested set of plain data structures (no objects). | ||||||||||||
| 194 | |||||||||||||
| 195 | =cut | ||||||||||||
| 196 | |||||||||||||
| 197 | 0 | ▶ | sub as_hash { | ||||||||||
|
Subroutine
as_hash: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 198 | 0 | my $self = shift; | |||||||||||
| 199 | 0 | my $context = shift; | |||||||||||
| 200 | return { | ||||||||||||
| 201 | 0 | type => lc($self->type), | |||||||||||
| 202 | endpoint => $self->endpoint, | ||||||||||||
| 203 | pattern => $self->pattern->as_hash, | ||||||||||||
| 204 | lhs => $self->lhs->as_hash, | ||||||||||||
| 205 | }; | ||||||||||||
| 206 | } | ||||||||||||
| 207 | |||||||||||||
| 208 | =item C<< type >> | ||||||||||||
| 209 | |||||||||||||
| 210 | Returns the type of this algebra expression. | ||||||||||||
| 211 | |||||||||||||
| 212 | =cut | ||||||||||||
| 213 | |||||||||||||
| 214 | 0 | ▶ | sub type { | ||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 215 | 0 | return 'SERVICE'; | |||||||||||
| 216 | } | ||||||||||||
| 217 | |||||||||||||
| 218 | =item C<< referenced_variables >> | ||||||||||||
| 219 | |||||||||||||
| 220 | Returns a list of the variable names used in this algebra expression. | ||||||||||||
| 221 | |||||||||||||
| 222 | =cut | ||||||||||||
| 223 | |||||||||||||
| 224 | 0 | ▶ | sub referenced_variables { | ||||||||||
|
Subroutine
referenced_variables: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 225 | 0 | my $self = shift; | |||||||||||
| 226 | 0 | my @list = $self->pattern->referenced_variables; | |||||||||||
| 227 | 0 | ▶ | push(@list, $self->lhs->referenced_variables) if ($self->lhs); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 228 | 0 | return RDF::Query::_uniq(@list); | |||||||||||
| 229 | } | ||||||||||||
| 230 | |||||||||||||
| 231 | =item C<< potentially_bound >> | ||||||||||||
| 232 | |||||||||||||
| 233 | Returns a list of the variable names used in this algebra expression that will | ||||||||||||
| 234 | bind values during execution. | ||||||||||||
| 235 | |||||||||||||
| 236 | =cut | ||||||||||||
| 237 | |||||||||||||
| 238 | 0 | ▶ | sub potentially_bound { | ||||||||||
|
Subroutine
potentially_bound: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 239 | 0 | my $self = shift; | |||||||||||
| 240 | 0 | my @list = RDF::Query::_uniq($self->pattern->potentially_bound); | |||||||||||
| 241 | 0 | ▶ | if ($self->lhs) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 242 | 0 | push(@list, $self->lhs->potentially_bound); | |||||||||||
| 243 | } | ||||||||||||
| 244 | 0 | return @list; | |||||||||||
| 245 | } | ||||||||||||
| 246 | |||||||||||||
| 247 | =item C<< definite_variables >> | ||||||||||||
| 248 | |||||||||||||
| 249 | Returns a list of the variable names that will be bound after evaluating this algebra expression. | ||||||||||||
| 250 | |||||||||||||
| 251 | =cut | ||||||||||||
| 252 | |||||||||||||
| 253 | 0 | ▶ | sub definite_variables { | ||||||||||
|
Subroutine
definite_variables: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 254 | 0 | my $self = shift; | |||||||||||
| 255 | return RDF::Query::_uniq( | ||||||||||||
| 256 | 0 | ▶ | map { $_->name } grep { $_->isa('RDF::Query::Node::Variable') } ($self->graph), | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 257 | $self->pattern->definite_variables, | ||||||||||||
| 258 | ($self->lhs ? $self->lhs->definite_variables : ()), | ||||||||||||
| 259 | ); | ||||||||||||
| 260 | } | ||||||||||||
| 261 | |||||||||||||
| 262 | |||||||||||||
| 263 | =item C<< qualify_uris ( \%namespaces, $base_uri ) >> | ||||||||||||
| 264 | |||||||||||||
| 265 | Returns a new algebra pattern where all referenced Resource nodes representing | ||||||||||||
| 266 | QNames (ns:local) are qualified using the supplied %namespaces. | ||||||||||||
| 267 | |||||||||||||
| 268 | =cut | ||||||||||||
| 269 | |||||||||||||
| 270 | 0 | ▶ | sub qualify_uris { | ||||||||||
|
Subroutine
qualify_uris: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 271 | 0 | my $self = shift; | |||||||||||
| 272 | 0 | my $class = ref($self); | |||||||||||
| 273 | 0 | my $ns = shift; | |||||||||||
| 274 | 0 | my $base_uri = shift; | |||||||||||
| 275 | |||||||||||||
| 276 | 0 | my $pattern = $self->pattern->qualify_uris( $ns, $base_uri ); | |||||||||||
| 277 | 0 | my $endpoint = $self->endpoint; | |||||||||||
| 278 | 0 | my $silent = $self->silent; | |||||||||||
| 279 | 0 | my $uri = $endpoint->uri; | |||||||||||
| 280 | 0 | ▶ | if (my $ggp = $self->lhs) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 281 | 0 | return $class->new( $endpoint, $pattern, $silent, $ggp->qualify_uris($ns, $base_uri) ); | |||||||||||
| 282 | } else { | ||||||||||||
| 283 | 0 | return $class->new( $endpoint, $pattern, $silent ); | |||||||||||
| 284 | } | ||||||||||||
| 285 | } | ||||||||||||
| 286 | |||||||||||||
| 287 | 36 | 1; | |||||||||||
| 288 | |||||||||||||
| 289 | __END__ | ||||||||||||