RDF/Trine/Statement/Quad.pm

filter: Statementstmt 62.8% 44 / 70 Branchbran 35.7% 5 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.2% 13 / 16 Podpod 100% 8 / 8 totaltotal 64.8% 70 / 108 CC 10 SCAR 20.6
CC
10
Cov
58%
__ANON__
30.0
from_redland
6.0
new
4.1
CRAP 7.8
« RDF/Trine/Node/Resource.pm ↑ Summary RDF/Trine/Error.pm »
1 # RDF::Trine::Statement::Quad
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Trine::Statement::Quad - Class for quads and quad patterns
7  
8 =head1 VERSION
9  
10 This document describes RDF::Trine::Statement::Quad version 1.019
11  
12 =cut
13  
14 package RDF::Trine::Statement::Quad;
15  
16 68 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 68 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 68 ▶use base qw(RDF::Trine::Statement);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 68 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 68 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 ######################################################################
25  
26 68 our ($VERSION);
27 68 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
28 68 $VERSION = '1.019';
29 }
30  
31 ######################################################################
32  
33 =head1 METHODS
34  
35 Beyond the methods documented below, this class inherits methods from the
36 L<RDF::Trine::Statement> class.
37  
38 =over 4
39  
40 =cut
41  
42 =item C<new ( $s, $p, $o, $c )>
43  
44 Returns a new Quad structure.
45  
46 =cut
47  
48 7801 ▶sub new {
Subroutine new: called CC=4 SCAR=14.0
Pod documented
49 7801 my $class = shift;
50 7801 my @nodes = @_;
51 7801 ▶ unless (scalar(@nodes) == 4) {
Branch: 1 branch
BranchTrueFalseTotal
unless (scalar @nodes == 4) 1 7800 7801
52 1 throw RDF::Trine::Error::MethodInvocationError -text => "Quad constructor must have four node arguments";
53 }
54 7800 my @names = qw(subject predicate object context);
55 7800 foreach my $i (0 .. 3) {
56 31200 ▶ unless (defined($nodes[ $i ])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $nodes[$i]) 0 31200 31200
57 0 $nodes[ $i ] = RDF::Trine::Node::Variable->new($names[ $i ]);
58 }
59 }
60
61 7800 return bless( [ @nodes ], $class );
62 }
63  
64 =item C<< nodes >>
65  
66 Returns the subject, predicate and object of the triple pattern.
67  
68 =cut
69  
70 8674 ▶sub nodes {
Subroutine nodes: called CC=1 SCAR=0.0
Pod documented
71 8674 my $self = shift;
72 8674 return @$self;
73 }
74  
75 =item C<< node_names >>
76  
77 Returns the method names for accessing the nodes of this statement.
78  
79 =cut
80  
81 1 ▶sub node_names {
Subroutine node_names: called CC=1 SCAR=0.0
Pod documented
82 1 return qw(subject predicate object context);
83 }
84  
85 =item C<< graph >>
86  
87 =item C<< context >>
88  
89 Returns the graph node of the quad pattern.
90  
91 =cut
92  
93 10491 ▶sub context {
Subroutine context: called CC=2 SCAR=6.9
Pod documented
94 10491 my $self = shift;
95 10491 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 10490 10491
96 1 $self->[3] = shift;
97 }
98 10491 return $self->[3];
99 }
100 68 *graph = \&context;
101  
102 =item C<< sse >>
103  
104 Returns the SSE string for this algebra expression.
105  
106 =cut
107  
108 4398 ▶sub sse {
Subroutine sse: called CC=1 SCAR=0.0
Pod documented
109 4398 my $self = shift;
110 4398 my $context = shift;
111
112 4398 my @nodes = $self->nodes;
113 4398 my @sse = map { $_->sse( $context ) } (@nodes);
114 4398 return sprintf( '(quad %s %s %s %s)', @sse );
115 }
116  
117 =item C<< type >>
118  
119 Returns the type of this algebra expression.
120  
121 =cut
122  
123 221 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
124 221 return 'QUAD';
125 }
126  
127 =item C<< clone >>
128  
129 =cut
130  
131 0 ▶sub clone {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
132 0 my $self = shift;
133 0 my $class = ref($self);
134 0 return $class->new( $self->nodes );
135 }
136  
137 =item C<< from_redland ( $statement, $name ) >>
138  
139 Given a RDF::Redland::Statement object and a graph name, returns a perl-native
140 RDF::Trine::Statement::Quad object.
141  
142 =cut
143  
144 0 ▶sub from_redland {
Subroutine from_redland: not called CC=2 SCAR=17.9
Pod documented
145 0 my $self = shift;
146 0 my $rstmt = shift;
147 0 my $graph = shift;
148
149 0 my $rs = $rstmt->subject;
150 0 my $rp = $rstmt->predicate;
151 0 my $ro = $rstmt->object;
152
153 0 ▶ my $cast = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
154 0 my $node = shift;
155 0 my $type = $node->type;
156 0 ▶ if ($type == $RDF::Redland::Node::Type_Resource) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type == $RDF::Redland::Node::Type_Resource) { } 0 0 0
elsif ($type == $RDF::Redland::Node::Type_Blank) { } 0 0 0
elsif ($type == $RDF::Redland::Node::Type_Literal) { } 0 0 0
157 0 return RDF::Trine::Node::Resource->new( $node->uri->as_string );
158 } elsif ($type == $RDF::Redland::Node::Type_Blank) {
159 0 return RDF::Trine::Node::Blank->new( $node->blank_identifier );
160 } elsif ($type == $RDF::Redland::Node::Type_Literal) {
161 0 my $lang = $node->literal_value_language;
162 0 my $dturi = $node->literal_datatype;
163 0 ▶ my $dt = ($dturi)
Branch: 1 branch
BranchTrueFalseTotal
$dturi ? : 0 0 0
164 ? $dturi->as_string
165 : undef;
166 0 return RDF::Trine::Node::Literal->new( $node->literal_value, $lang, $dt );
167 } else {
168 0 croak 'Unknown node type in statement conversion';
169 }
170 0 };
171
172 0 my @nodes;
173 0 foreach my $n ($rs, $rp, $ro) {
174 0 push(@nodes, $cast->( $n ));
175 }
176 0 my $st = $self->new( @nodes, $graph );
177 0 return $st;
178 }
179  
180  
181  
182  
183 68 1;
184  
185 __END__
« RDF/Trine/Node/Resource.pm ↑ Summary RDF/Trine/Error.pm »