Template/Unit.pm

filter: Statementstmt 48.4% 16 / 33 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 55.5% 5 / 9 Podpod 100% 4 / 4 totaltotal 48.0% 25 / 52 CC 4 SCAR 15.4
CC
4
Cov
41%
results
12.0
endpoint
6.0
pattern
2.0
CRAP 4.7
« Template/Document.pm ↑ Summary Template/SimpleQuery.pm »
1 package RDF::RDFa::Template::Unit;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 RDF::RDFa::Template::Unit - An individual graph pattern of an RDFa Template
11  
12 =cut
13  
14  
15 2 ▶use RDF::Query::Algebra::BasicGraphPattern;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=2.2
Pod documented
18 0 my ($class, %args) = @_;
19 2 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 my $self = {
21 0 PATTERN => RDF::Query::Algebra::BasicGraphPattern->new(@{$args{triples}}),
22 ENDPOINT => $args{endpoint},
23 DOC_GRAPH => $args{doc_graph},
24 0 ITERATOR => {},
25 };
26  
27 0 bless ($self, $class);
28 0 return $self;
29 }
30  
31  
32 =head1 SYNOPSIS
33  
34 This class holds an individual graph pattern of an RDFa Template. This
35 has several elements, a Basic Graph Pattern, a query endpoint and a
36 graph name from the RDFa document.
37  
38 $doc = RDF::RDFa::Template::Unit->new(triples => \@triples,
39 endpoint => 'http://dbpedia.org/sparql',
40 doc_graph => 'http://example.org/graph'
41  
42  
43  
44 =head1 METHODS
45  
46 =head2 new
47  
48 The constructor. Takes three named arguments:
49  
50 =over
51  
52 =item C<triples>
53  
54 An arrayref with L<RDF::Trine::Statement>s, or subclasses thereof.
55  
56 =item C<endpoint>
57  
58 A SPARQL endpoint can optionally be set in the constructor.
59  
60 =item C<doc_graph>
61  
62 A graph name for the document. TODO: Not used.
63  
64 =back
65  
66 =head2 pattern
67  
68 Will return an L<RDF::Query::Algebra::BasicGraphPattern> object
69 containing the Basic Graph Pattern of this unit.
70  
71 =cut
72  
73 0 ▶sub pattern {
Subroutine pattern: not called CC=1 SCAR=6.9
Pod documented
74 0 my $self = shift;
75 0 return $self->{PATTERN};
76 }
77  
78 =head2 endpoint
79  
80 If no argument is given and the unit contains a SPARQL endpoint, this will
81 be returned as a string. If a string argument is given, this will be
82 used to set the endpoint URL.
83  
84 =cut
85  
86 0 ▶sub endpoint {
Subroutine endpoint: not called CC=2 SCAR=17.9
Pod documented
87 0 my ($self, $endpoint) = @_;
88 0 ▶ if ($endpoint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($endpoint) 0 0 0
89 0 $self->{ENDPOINT} = $endpoint;
90 }
91 0 return $self->{ENDPOINT};
92 }
93  
94 =head2 results
95  
96 Used to set and get a L<RDF::Trine::Iterator> object that can be used
97 to explore the query results for this unit.
98  
99 To set the iterator, send a L<RDF::Trine::Iterator> object as the only
100 argument.
101  
102 If no argument is given, this will return an L<RDF::Trine::Iterator>
103 object that can be used to explore the query results for this unit, or
104 an empty hashref if no results are available.
105  
106 =cut
107  
108  
109 0 ▶sub results {
Subroutine results: not called CC=3 SCAR=24.8
Pod documented
110 0 my ($self, $iterator) = @_;
111 0 ▶ if ($iterator) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iterator) 0 0 0
112 0 ▶ if ($iterator->isa('RDF::Trine::Iterator')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($iterator->isa('RDF::Trine::Iterator')) { } 0 0 0
113 0 $self->{ITERATOR} = $iterator;
114 } else {
115 0 croak "Argument is not a RDF::Trine::Iterator";
116 }
117 }
118 0 return $self->{ITERATOR};
119 }
120  
121  
122 =head1 AUTHOR
123  
124 Kjetil Kjernsmo, C<< <kjetilk at cpan.org> >>
125  
126  
127 =head1 COPYRIGHT & LICENSE
128  
129 Copyright 2010 Kjetil Kjernsmo.
130  
131 This program is free software; you can redistribute it and/or modify it
132 under the same terms as Perl itself.
133  
134 =cut
135  
136 2 1;
« Template/Document.pm ↑ Summary Template/SimpleQuery.pm »