Query/Node.pm

filter: Statementstmt 62.3% 48 / 77 Branchbran 40.0% 8 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 70.0% 14 / 20 Podpod 100% 9 / 9 totaltotal 62.6% 82 / 131 CC 13 SCAR 18.2
CC
13
Cov
58%
from_attean
19.9
compare
12.0
from_trine
6.2
CRAP 6.2
« Query/Algebra/GroupGraphPattern.pm ↑ Summary Query/Algebra/Aggregate.pm »
1 # RDF::Query::Node
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Node - Base class for RDF Nodes
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Node version 2.919.
11  
12 =head1 METHODS
13  
14 =over 4
15  
16 =cut
17  
18 package RDF::Query::Node;
19  
20 36 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 36 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 36 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 36 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 36 ▶use RDF::Query::Node::Blank;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 36 ▶use RDF::Query::Node::Literal;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 36 ▶use RDF::Query::Node::Resource;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 36 ▶use RDF::Query::Node::Variable;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 36 our ($VERSION, @ISA, @EXPORT_OK, %EXPORT_TAGS);
31 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
32 36 $VERSION = '2.919';
33
34 36 require Exporter;
35 36 @ISA = qw(Exporter);
36 36 @EXPORT_OK = qw(iri blank literal variable);
37 36 %EXPORT_TAGS = ( 'all' => [qw(iri blank literal variable)] );
38 }
39  
40 =item C<< is_variable >>
41  
42 Returns true if this RDF node is a variable, false otherwise.
43  
44 =cut
45  
46 1875 ▶sub is_variable {
Subroutine is_variable: called CC=2 SCAR=7.1
Pod documented
47 1875 my $self = shift;
48 1875 ▶ return (blessed($self) and $self->isa('RDF::Query::Node::Variable'));
Condition66%2/3
builtin::blessed($self) && $self->isa('RDF::Query::Node::Variable')
!ll&&!rl&&r
01039836
MC/DC50%1/2
builtin::blessed($self) && $self->isa('RDF::Query::Node::Variable')
builtin::blessed($self) $self->isa('RDF::Query::Node::Variable')
Truth table66%2/3
A && B
A= builtin::blessed($self)B= $self->isa('RDF::Query::Node::Variable')
ABresult
0X0
100
111
49 }
50  
51 =item C<< compare ( $a, $b ) >>
52  
53 Returns -1, 0, or 1 if $a is less than, equal to, or greater than $b, respectively,
54 according to the SPARQL sorting rules.
55  
56 =cut
57  
58 sub compare {
59 my $a = shift;
60 my $b = shift;
61 warn 'compare';
62 for ($a, $b) {
63 unless ($_->isa('RDF::Query::Node')) {
64 $_ = RDF::Query::Node->from_trine( $_ );
65 }
66 }
67
68 local($RDF::Query::Node::Literal::LAZY_COMPARISONS) = 1;
69 return $a <=> $b;
70 }
71  
72 =item C<< from_trine ( $node ) >>
73  
74 Returns a new RDF::Query::Node object with the same value as $node, a
75 RDF::Trine::Node object. This essentially promotes C<< $node >> to a
76 node object with extra functionality provided by the RDF::Query package
77 (like SPARQL-defined ordering).
78  
79 =cut
80  
81 1117 ▶sub from_trine {
Subroutine from_trine: called CC=6 SCAR=18.3
Pod documented
82 1117 my $class = shift;
83 1117 my $n = shift;
84 1117 ▶ if ($n->isa('RDF::Trine::Node::Variable')) {
Branch: 5 branches
BranchTrueFalseTotal
if ($n->isa('RDF::Trine::Node::Variable')) { } 0 1117 1117
elsif ($n->isa('RDF::Trine::Node::Literal')) { } 293 824 1117
elsif ($n->isa('RDF::Trine::Node::Resource')) { } 372 452 824
elsif ($n->isa('RDF::Trine::Node::Blank')) { } 94 358 452
elsif ($n->isa('RDF::Trine::Node::Nil')) { } 358 0 358
85 0 return RDF::Query::Node::Variable->new( $n->name );
86 } elsif ($n->isa('RDF::Trine::Node::Literal')) {
87 293 return RDF::Query::Node::Literal->new( $n->literal_value, $n->literal_value_language, $n->literal_datatype );
88 } elsif ($n->isa('RDF::Trine::Node::Resource')) {
89 372 return RDF::Query::Node::Resource->new( $n->uri_value );
90 } elsif ($n->isa('RDF::Trine::Node::Blank')) {
91 94 return RDF::Query::Node::Blank->new( $n->blank_identifier );
92 } elsif ($n->isa('RDF::Trine::Node::Nil')) {
93 358 return $n;
94 } else {
95 36 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
96 0 Carp::confess "from_trine called with unrecognized node type:" . Dumper($n);
97 }
98 }
99  
100 =item C<< from_attean ( $node ) >>
101  
102 Likewise, but from L<Attean>.
103  
104 =cut
105  
106 0 ▶sub from_attean {
Subroutine from_attean: not called CC=5 SCAR=29.9
Pod documented
107 0 my $class = shift;
108 0 my $n = shift;
109 0 ▶ if ($n->does('Attean::API::Variable')) {
Branch: 4 branches
BranchTrueFalseTotal
if ($n->does('Attean::API::Variable')) { } 0 0 0
elsif ($n->does('Attean::API::Literal')) { } 0 0 0
elsif ($n->does('Attean::API::IRI')) { } 0 0 0
elsif ($n->does('Attean::API::Blank')) { } 0 0 0
110 0 return RDF::Query::Node::Variable->new( $n->value );
111 } elsif ($n->does('Attean::API::Literal')) {
112 0 return RDF::Query::Node::Literal->new( $n->value, $n->language, $n->datatype );
113 } elsif ($n->does('Attean::API::IRI')) {
114 0 return RDF::Query::Node::Resource->new( $n->as_string );
115 } elsif ($n->does('Attean::API::Blank')) {
116 0 return RDF::Query::Node::Blank->new( $n->value );
117 } else {
118 36 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
119 0 Carp::confess "from_attean called with unrecognized node type:" . Dumper($n);
120 }
121 }
122  
123 =item C<< explain >>
124  
125 Returns a string serialization of the node appropriate for display on the
126 command line. This method is primarily used by the C<< explain >> method of
127 the subclasses of RDF::Query::Plan.
128  
129 =cut
130  
131 0 ▶sub explain {
Subroutine explain: not called CC=1 SCAR=6.9
Pod documented
132 0 my $self = shift;
133 0 my $s = shift;
134 0 my $count = shift;
135 0 my $indent = $s x $count;
136 0 my $string = "${indent}" . $self->as_sparql . "\n";
137 0 return $string;
138 }
139  
140 =back
141  
142 =head1 FUNCTIONS
143  
144 =over 4
145  
146 =item C<< compare ( $node_a, $node_b ) >>
147  
148 Returns -1, 0, or 1 if $node_a sorts less than, equal to, or greater than
149 $node_b in the defined SPARQL ordering, respectively. This function may be
150 used as the function argument to C<<sort>>.
151  
152 =cut
153  
154 0 ▶sub compare {
Subroutine compare: not called CC=3 SCAR=24.8
Pod documented
155 0 my $a = shift;
156 0 my $b = shift;
157 0 warn 'compare';
158 0 for ($a, $b) {
159 0 ▶ unless ($_->isa('RDF::Query::Node')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($_->isa("RDF::Query::Node")) 0 0 0
160 0 $_ = RDF::Query::Node->from_trine( $_ );
161 }
162 }
163
164 0 local($RDF::Query::Node::Literal::LAZY_COMPARISONS) = 1;
165 0 return $a <=> $b;
166 }
167  
168  
169 =item C<< iri ( $iri ) >>
170  
171 Returns a RDF::Query::Node::Resource object with the given IRI value.
172  
173 =cut
174  
175 25 ▶sub iri {
Subroutine iri: called CC=1 SCAR=0.0
Pod documented
176 25 my $iri = shift;
177 25 return RDF::Query::Node::Resource->new( $iri );
178 }
179  
180 =item C<< blank ( $id ) >>
181  
182 Returns a RDF::Query::Node::Blank object with the given identifier.
183  
184 =cut
185  
186 0 ▶sub blank {
Subroutine blank: not called CC=1 SCAR=6.9
Pod documented
187 0 my $id = shift;
188 0 return RDF::Query::Node::Blank->new( $id );
189 }
190  
191 =item C<< literal ( $value, $lang, $dt ) >>
192  
193 Returns a RDF::Query::Node::Literal object with the given value and optional
194 language/datatype.
195  
196 =cut
197  
198 0 ▶sub literal {
Subroutine literal: not called CC=1 SCAR=6.9
Pod documented
199 0 return RDF::Query::Node::Literal->new( @_ );
200 }
201  
202 =item C<< variable ( $name ) >>
203  
204 Returns a RDF::Query::Node::Variable object with the given variable name.
205  
206 =cut
207  
208 0 ▶sub variable {
Subroutine variable: not called CC=1 SCAR=6.9
Pod documented
209 0 my $name = shift;
210 0 return RDF::Query::Node::Variable->new( $name );
211 }
212  
213  
214 36 1;
215  
216 __END__
« Query/Algebra/GroupGraphPattern.pm ↑ Summary Query/Algebra/Aggregate.pm »