| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# RDF::Query::Expression::Unary |
|
2
|
|
|
|
|
|
|
# ----------------------------------------------------------------------------- |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
RDF::Query::Expression::Unary - Class for unary expressions |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This document describes RDF::Query::Expression::Unary version 2.918. |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
package RDF::Query::Expression::Unary; |
|
15
|
|
|
|
|
|
|
|
|
16
|
36
|
|
|
36
|
|
133
|
use strict; |
|
|
36
|
|
|
|
|
45
|
|
|
|
36
|
|
|
|
|
855
|
|
|
17
|
36
|
|
|
36
|
|
117
|
use warnings; |
|
|
36
|
|
|
|
|
42
|
|
|
|
36
|
|
|
|
|
767
|
|
|
18
|
36
|
|
|
36
|
|
116
|
no warnings 'redefine'; |
|
|
36
|
|
|
|
|
48
|
|
|
|
36
|
|
|
|
|
1146
|
|
|
19
|
36
|
|
|
36
|
|
137
|
use base qw(RDF::Query::Expression); |
|
|
36
|
|
|
|
|
50
|
|
|
|
36
|
|
|
|
|
2159
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
36
|
|
|
36
|
|
149
|
use Data::Dumper; |
|
|
36
|
|
|
|
|
47
|
|
|
|
36
|
|
|
|
|
1562
|
|
|
22
|
36
|
|
|
36
|
|
134
|
use Scalar::Util qw(blessed); |
|
|
36
|
|
|
|
|
52
|
|
|
|
36
|
|
|
|
|
1297
|
|
|
23
|
36
|
|
|
36
|
|
316
|
use Carp qw(carp croak confess); |
|
|
36
|
|
|
|
|
62
|
|
|
|
36
|
|
|
|
|
2019
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
###################################################################### |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our ($VERSION); |
|
28
|
|
|
|
|
|
|
BEGIN { |
|
29
|
36
|
|
|
36
|
|
10970
|
$VERSION = '2.918'; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
###################################################################### |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Beyond the methods documented below, this class inherits methods from the |
|
37
|
|
|
|
|
|
|
L<RDF::Query::Expression> class. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over 4 |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=item C<< sse >> |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Returns the SSE string for this algebra expression. |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub sse { |
|
50
|
3
|
|
|
3
|
1
|
5
|
my $self = shift; |
|
51
|
3
|
|
|
|
|
5
|
my $context = shift; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return sprintf( |
|
54
|
|
|
|
|
|
|
'(%s %s)', |
|
55
|
|
|
|
|
|
|
$self->op, |
|
56
|
3
|
|
|
|
|
12
|
map { $_->sse( $context ) } $self->operands, |
|
|
3
|
|
|
|
|
11
|
|
|
57
|
|
|
|
|
|
|
); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item C<< as_sparql >> |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Returns the SPARQL string for this algebra expression. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub as_sparql { |
|
67
|
2
|
|
|
2
|
1
|
2
|
my $self = shift; |
|
68
|
2
|
|
|
|
|
6
|
my $context = shift; |
|
69
|
2
|
|
|
|
|
2
|
my $indent = shift; |
|
70
|
2
|
|
|
|
|
7
|
my $op = $self->op; |
|
71
|
2
|
|
|
|
|
9
|
return sprintf("($op %s)", map { $_->as_sparql( $context, $indent ) } $self->operands); |
|
|
2
|
|
|
|
|
10
|
|
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item C<< evaluate ( $query, \%bound ) >> |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Evaluates the expression using the supplied bound variables. |
|
77
|
|
|
|
|
|
|
Will return a RDF::Query::Node object. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub evaluate { |
|
82
|
6
|
|
|
6
|
1
|
13
|
my $self = shift; |
|
83
|
6
|
|
|
|
|
5
|
my $query = shift; |
|
84
|
6
|
|
|
|
|
6
|
my $bound = shift; |
|
85
|
6
|
|
|
|
|
7
|
my $context = shift; |
|
86
|
6
|
|
|
|
|
15
|
my $op = $self->op; |
|
87
|
6
|
|
|
|
|
17
|
my ($data) = $self->operands; |
|
88
|
6
|
100
|
100
|
|
|
31
|
if ($op eq '+' or $op eq '-') { |
|
|
|
50
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
my $l = $data->isa('RDF::Query::Algebra') |
|
90
|
|
|
|
|
|
|
? $data->evaluate( $query, $bound, $context, @_ ) |
|
91
|
|
|
|
|
|
|
: ($data->isa('RDF::Query::Node::Variable')) |
|
92
|
2
|
50
|
|
|
|
13
|
? $bound->{ $data->name } |
|
|
|
50
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
: $data; |
|
94
|
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
3
|
my $value; |
|
96
|
2
|
100
|
|
|
|
5
|
if ($op eq '+') { |
|
|
|
50
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
4
|
$value = $l->numeric_value; |
|
98
|
|
|
|
|
|
|
} elsif ($op eq '-') { |
|
99
|
1
|
|
|
|
|
3
|
$value = -1 * $l->numeric_value; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
2
|
|
|
|
|
6
|
return RDF::Query::Node::Literal->new( $value, undef, $l->literal_datatype ); |
|
102
|
|
|
|
|
|
|
} elsif ($op eq '!') { |
|
103
|
4
|
|
|
|
|
9
|
my $alg = RDF::Query::Expression::Function->new( "sparql:ebv", $data ); |
|
104
|
4
|
|
|
|
|
13
|
my $bool = $alg->evaluate( $query, $bound, $context, @_ ); |
|
105
|
4
|
100
|
|
|
|
7
|
if ($bool->literal_value eq 'true') { |
|
106
|
1
|
|
|
|
|
7
|
return RDF::Query::Node::Literal->new( 'false', undef, 'http://www.w3.org/2001/XMLSchema#boolean' ); |
|
107
|
|
|
|
|
|
|
} else { |
|
108
|
3
|
|
|
|
|
14
|
return RDF::Query::Node::Literal->new( 'true', undef, 'http://www.w3.org/2001/XMLSchema#boolean' ); |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
} else { |
|
111
|
0
|
|
|
|
|
|
warn "unknown unary op: $op"; |
|
112
|
0
|
|
|
|
|
|
throw RDF::Query::Error::ExecutionError -text => "Unknown unary op '$op'"; |
|
113
|
|
|
|
|
|
|
} |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
__END__ |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=back |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 AUTHOR |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Gregory Todd Williams <gwilliams@cpan.org> |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut |