Query/Node/Resource.pm

filter: Statementstmt 93.4% 71 / 76 Branchbran 61.1% 11 / 18 Conditioncond 100% 4 / 4 MC/DCmcdc 100% 2 / 2 Subroutinesub 90.9% 20 / 22 Podpod 100% 2 / 2 totaltotal 88.7% 110 / 124 CC 13 SCAR 13.0
CC
13
Cov
88%
as_sparql
8.1
_cmp
6.3
__ANON__
2.0
CRAP 3.7
« Query/Plan/Union.pm ↑ Summary Query/Algebra/Filter.pm »
1 # RDF::Query::Node::Resource
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Query::Node::Resource - RDF Node class for resources
7  
8 =head1 VERSION
9  
10 This document describes RDF::Query::Node::Resource version 2.919.
11  
12 =cut
13  
14 package RDF::Query::Node::Resource;
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::Node RDF::Trine::Node::Resource);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 36 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 36 ▶use Encode;
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::Parser::SPARQL;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 36 ▶use Scalar::Util qw(blessed reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 36 ▶use Carp qw(carp croak confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 ######################################################################
29  
30 36 our ($VERSION);
31 36 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
32 36 $VERSION = '2.919';
33 }
34  
35 ######################################################################
36  
37  
38 =head1 METHODS
39  
40 Beyond the methods documented below, this class inherits methods from the
41 L<RDF::Query::Node> and L<RDF::Trine::Node::Resource> classes.
42  
43 =over 4
44  
45 =cut
46  
47 36 ▶use overload '<=>' => \&_cmp,
Subroutine BEGIN: called CC=1 SCAR=0.0
48 'cmp' => \&_cmp,
49 4 ▶ '<' => sub { _cmp(@_) == -1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
50 1 ▶ '>' => sub { _cmp(@_) == 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
51 1 ▶ '!=' => sub { _cmp(@_) != 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
52 18 ▶ '==' => sub { _cmp(@_) == 0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
53 0 ▶ '+' => sub { $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 1494 ▶ '""' => sub { $_[0]->sse },
Subroutine __ANON__: called CC=1 SCAR=0.0
55 36 ;
56  
57 25 ▶sub _cmp {
Subroutine _cmp: called CC=6 SCAR=18.5
58 25 my $a = shift;
59 25 my $b = shift;
60 25 ▶ return 1 unless blessed($b);
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($b) 0 25 25
61 25 ▶ return -1 if ($b->isa('RDF::Query::Node::Literal'));
Branch: 1 branch
BranchTrueFalseTotal
if $b->isa("RDF::Query::Node::Literal") 3 22 25
62 22 ▶ return -1 if ($b->isa('RDF::Trine::Node::Nil'));
Branch: 1 branch
BranchTrueFalseTotal
if $b->isa("RDF::Trine::Node::Nil") 0 22 22
63 22 ▶ return 1 if ($b->isa('RDF::Query::Node::Blank'));
Branch: 1 branch
BranchTrueFalseTotal
if $b->isa("RDF::Query::Node::Blank") 0 22 22
64 22 ▶ return 0 unless ($b->isa('RDF::Query::Node::Resource'));
Branch: 1 branch
BranchTrueFalseTotal
unless $b->isa("RDF::Query::Node::Resource") 0 22 22
65 22 my $cmp = $a->uri_value cmp $b->uri_value;
66 22 return $cmp;
67 }
68  
69 =item C<< as_sparql >>
70  
71 Returns the SPARQL string for this node.
72  
73 =cut
74  
75 283 ▶sub as_sparql {
Subroutine as_sparql: called CC=8 SCAR=20.9
Pod documented
76 283 my $self = shift;
77 283 my $PNLOCAL = $RDF::Query::Parser::SPARQL::r_PN_LOCAL;
78 283 ▶ my $context = shift || {};
Condition100%2/2
shift() || {}
l!l
24934
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
79 283 ▶ if ($context) {
Branch: 1 branch
BranchTrueFalseTotal
if ($context) 283 0 283
80 283 my $uri = $self->uri_value;
81 283 ▶ my $ns = $context->{namespaces} || {};
Condition100%2/2
$context->{'namespaces'} || {}
l!l
43240
MC/DC100%1/1
$context->{'namespaces'} || {}
$context->{'namespaces'}
Truth table100%2/2
A
A= $context->{'namespaces'}
Aresult
11
00
82 283 my %ns = %$ns;
83 283 foreach my $k (keys %ns) {
84 36 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
85 47 ▶ if ($k eq '__DEFAULT__') {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq "__DEFAULT__") 0 47 47
86 0 $k = '';
87 }
88 47 my $v = $ns{ $k };
89 47 ▶ if (index($uri, $v) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($uri, $v) == 0) 41 6 47
90 41 my $local = substr($uri, length($v));
91
92 41 ▶ if ($local =~ /^(?:$PNLOCAL)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($local =~ /^(?:$PNLOCAL)$/) 41 0 41
93 41 my $qname = join(':', $k, $local);
94 41 return $qname;
95 }
96 }
97 }
98 }
99
100 242 my $string = URI->new( encode_utf8($self->uri_value) )->canonical;
101 242 my $sparql = '<' . $string . '>';
102 242 return $sparql;
103 }
104  
105 =item C<< as_hash >>
106  
107 Returns the query as a nested set of plain data structures (no objects).
108  
109 =cut
110  
111 0 ▶sub as_hash {
Subroutine as_hash: not called CC=1 SCAR=6.9
Pod documented
112 0 my $self = shift;
113 0 my $context = shift;
114 return {
115 0 type => 'node',
116 iri => $self->uri_value,
117 };
118 }
119  
120 36 1;
121  
122 __END__
« Query/Plan/Union.pm ↑ Summary Query/Algebra/Filter.pm »