Query/Expression/Unary.pm

filter: Statementstmt 96.3% 52 / 54 Branchbran 71.4% 10 / 14 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 3 / 3 totaltotal 93.1% 81 / 87 CC 9 SCAR 16.0
CC
9
Cov
92%
evaluate
9.3
BEGIN
1.0
BEGIN
1.0
CRAP 5.0
« Query/Plan/Project.pm ↑ Summary Query/Algebra/Triple.pm »
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.919.
11  
12 =cut
13  
14 package RDF::Query::Expression::Unary;
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 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 36 ▶use base qw(RDF::Query::Expression);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 36 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 36 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 ######################################################################
26  
27 36 our ($VERSION);
28 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
29 36 $VERSION = '2.919';
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 3 ▶sub sse {
Subroutine sse: called CC=1 SCAR=0.0
Pod documented
50 3 my $self = shift;
51 3 my $context = shift;
52
53 return sprintf(
54 '(%s %s)',
55 $self->op,
56 3 map { $_->sse( $context ) } $self->operands,
57 );
58 }
59  
60 =item C<< as_sparql >>
61  
62 Returns the SPARQL string for this algebra expression.
63  
64 =cut
65  
66 2 ▶sub as_sparql {
Subroutine as_sparql: called CC=1 SCAR=0.0
Pod documented
67 2 my $self = shift;
68 2 my $context = shift;
69 2 my $indent = shift;
70 2 my $op = $self->op;
71 2 return sprintf("($op %s)", map { $_->as_sparql( $context, $indent ) } $self->operands);
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 6 ▶sub evaluate {
Subroutine evaluate: called CC=9 SCAR=22.3
Pod documented
82 6 my $self = shift;
83 6 my $query = shift;
84 6 my $bound = shift;
85 6 my $context = shift;
86 6 my $op = $self->op;
87 6 my ($data) = $self->operands;
88 6 ▶ if ($op eq '+' or $op eq '-') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '+' or $op eq '-') { } 2 4 6
elsif ($op eq '!') { } 4 0 4
Condition100%3/3
$op eq "+" or $op eq "-"
l!l&&r!l&&!r
114
MC/DC100%2/2
$op eq "+" or $op eq "-"
$op eq "+" $op eq "-"
Truth table100%3/3
A or B
A= $op eq "+"B= $op eq "-"
ABresult
1X1
011
000
89 my $l = $data->isa('RDF::Query::Algebra')
90 ? $data->evaluate( $query, $bound, $context, @_ )
91 : ($data->isa('RDF::Query::Node::Variable'))
92 2 ▶ ? $bound->{ $data->name }
Branch: 2 branches
BranchTrueFalseTotal
$data->isa('RDF::Query::Algebra') ? : 0 2 2
$data->isa('RDF::Query::Node::Variable') ? : 0 2 2
93 : $data;
94
95 2 my $value;
96 2 ▶ if ($op eq '+') {
Branch: 2 branches
BranchTrueFalseTotal
if ($op eq '+') { } 1 1 2
elsif ($op eq '-') { } 1 0 1
97 1 $value = $l->numeric_value;
98 } elsif ($op eq '-') {
99 1 $value = -1 * $l->numeric_value;
100 }
101 2 return RDF::Query::Node::Literal->new( $value, undef, $l->literal_datatype );
102 } elsif ($op eq '!') {
103 4 my $alg = RDF::Query::Expression::Function->new( "sparql:ebv", $data );
104 4 my $bool = $alg->evaluate( $query, $bound, $context, @_ );
105 4 ▶ if ($bool->literal_value eq 'true') {
Branch: 1 branch
BranchTrueFalseTotal
if ($bool->literal_value eq 'true') { } 1 3 4
106 1 return RDF::Query::Node::Literal->new( 'false', undef, 'http://www.w3.org/2001/XMLSchema#boolean' );
107 } else {
108 3 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 36 1;
118  
119 __END__
« Query/Plan/Project.pm ↑ Summary Query/Algebra/Triple.pm »