RDF/Trine.pm

filter: Statementstmt 100% 101 / 101 Branchbran 70.0% 7 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 31 / 31 Podpod 100% 7 / 7 totaltotal 95.4% 147 / 154 CC 7 SCAR 3.7
CC
7
Cov
96%
default_useragent
3.2
_uniq
3.0
BEGIN
2.0
CRAP 1.4
« RDF/Trine/Node/Blank.pm ↑ Summary RDF/Trine/Parser/Turtle/Constants.pm »
1 # RDF::Trine
2 # -----------------------------------------------------------------------------
3  
4 =head1 NAME
5  
6 RDF::Trine - An RDF Framework for Perl
7  
8 =head1 VERSION
9  
10 This document describes RDF::Trine version 1.019
11  
12 =head1 SYNOPSIS
13  
14 use RDF::Trine;
15
16 my $store = RDF::Trine::Store::Memory->new();
17 my $model = RDF::Trine::Model->new($store);
18
19 # parse some web data into the model, and print the count of resulting RDF statements
20 RDF::Trine::Parser->parse_url_into_model( 'http://kasei.us/about/foaf.xrdf', $model );
21 print $model->size . " RDF statements parsed\n";
22
23 # Create a namespace object for the foaf vocabulary
24 my $foaf = RDF::Trine::Namespace->new( 'http://xmlns.com/foaf/0.1/' );
25
26 # Create a node object for the FOAF name property
27 my $pred = $foaf->name;
28 # alternatively:
29 # my $pred = RDF::Trine::Node::Resource->new('http://xmlns.com/foaf/0.1/name');
30
31 # Create an iterator for all the statements in the model with foaf:name as the predicate
32 my $iter = $model->get_statements(undef, $pred, undef);
33
34 # Now print the results
35 print "Names of things:\n";
36 while (my $st = $iter->next) {
37 my $s = $st->subject;
38 my $name = $st->object;
39
40 # $s and $name have string overloading, so will print correctly
41 print "The name of $s is $name\n";
42 }
43  
44 =head1 DESCRIPTION
45  
46 RDF::Trine provides an Resource Descriptive Framework (RDF) with an emphasis on
47 extensibility, API stability, and the presence of a test suite. The package
48 consists of several components:
49  
50 =over 4
51  
52 =item
53  
54 L<RDF::Trine::Model> - RDF model providing access to a triple store. This module would typically be used to access an existing store by a developer looking to "Just get stuff done."
55  
56 =item
57  
58 L<RDF::Trine::Parser> - RDF parsers for various serialization formats including RDF/XML, Turtle, RDFa, and RDF/JSON.
59  
60 =item
61  
62 L<RDF::Trine::Store::Memory> - An in-memory, non-persistant triple store. Typically used for temporary data.
63  
64 =item
65  
66 L<RDF::Trine::Store::DBI> - A triple store for MySQL, PostgreSQL, and SQLite, based on the relational schema used by Redland. Typically used to for large, persistent data.
67  
68 =item
69  
70 L<RDF::Trine::Iterator> - Iterator classes for variable bindings and RDF statements, used by RDF::Trine::Store, RDF::Trine::Model, and RDF::Query.
71  
72 =item
73  
74 L<RDF::Trine::Namespace> - A convenience class for easily constructing RDF::Trine::Node::Resource objects from URI namespaces.
75  
76 =back
77  
78 =cut
79  
80 package RDF::Trine;
81  
82 68 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
83 68 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 68 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
85 68 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
86 68 ▶use Module::Load::Conditional qw[can_load];
Subroutine BEGIN: called CC=1 SCAR=0.0
87 68 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
88  
89 68 our ($debug, @ISA, $VERSION, @EXPORT_OK);
90 68 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
91 68 $debug = 0;
92 68 $VERSION = '1.019';
93
94 68 require Exporter;
95 68 @ISA = qw(Exporter);
96 68 @EXPORT_OK = qw(iri blank literal variable statement store UNION_GRAPH NIL_GRAPH);
97
98 68 ▶ unless ($ENV{RDFTRINE_NO_REDLAND}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"RDFTRINE_NO_REDLAND"}) 68 0 68
99 68 can_load( modules => {
100 'RDF::Redland' => undef,
101 'RDF::Trine::Store::Redland' => undef,
102 'RDF::Trine::Parser::Redland' => undef,
103 } );
104 }
105 }
106  
107 68 ▶use constant UNION_GRAPH => 'tag:gwilliams@cpan.org,2010-01-01:RT:ALL';
Subroutine BEGIN: called CC=1 SCAR=0.0
108 68 ▶use constant NIL_GRAPH => 'tag:gwilliams@cpan.org,2010-01-01:RT:NIL';
Subroutine BEGIN: called CC=1 SCAR=0.0
109  
110 68 ▶use Log::Log4perl qw(:easy);
Subroutine BEGIN: called CC=1 SCAR=0.0
111 68 ▶if (! Log::Log4perl::initialized() ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Log::Log4perl::initialized()) 68 0 68
112 68 Log::Log4perl->easy_init($ERROR);
113 }
114  
115 68 ▶use RDF::Trine::Graph;
Subroutine BEGIN: called CC=1 SCAR=0.0
116 68 ▶use RDF::Trine::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 68 ▶use RDF::Trine::Serializer;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 68 ▶use RDF::Trine::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
119 68 ▶use RDF::Trine::Statement;
Subroutine BEGIN: called CC=1 SCAR=0.0
120 68 ▶use RDF::Trine::Namespace;
Subroutine BEGIN: called CC=1 SCAR=0.0
121 68 ▶use RDF::Trine::NamespaceMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
122 68 ▶use RDF::Trine::Iterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 68 ▶use RDF::Trine::Store;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 68 ▶use RDF::Trine::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
125 68 ▶use RDF::Trine::Model;
Subroutine BEGIN: called CC=1 SCAR=0.0
126  
127 68 ▶use RDF::Trine::Parser::Turtle;
Subroutine BEGIN: called CC=1 SCAR=0.0
128 68 ▶use RDF::Trine::Parser::TriG;
Subroutine BEGIN: called CC=1 SCAR=0.0
129  
130  
131 762 ▶sub _uniq {
Subroutine _uniq: called CC=3 SCAR=11.0
132 762 my %seen;
133 my @data;
134 762 foreach (@_) {
135 2045 ▶ push(@data, $_) unless ($seen{ $_ }++);
Branch: 1 branch
BranchTrueFalseTotal
unless $seen{$_}++ 2001 44 2045
136 }
137 762 return @data;
138 }
139  
140 =head1 FUNCTIONS
141  
142 =over 4
143  
144 =item C<< iri ( $iri ) >>
145  
146 Returns a L<RDF::Trine::Node::Resource> object with the given IRI value.
147  
148 =cut
149  
150 114 ▶sub iri {
Subroutine iri: called CC=1 SCAR=0.0
Pod documented
151 114 my $iri = shift;
152 114 return RDF::Trine::Node::Resource->new( $iri );
153 }
154  
155 =item C<< blank ( $id ) >>
156  
157 Returns a L<RDF::Trine::Node::Blank> object with the given identifier.
158  
159 =cut
160  
161 10 ▶sub blank {
Subroutine blank: called CC=1 SCAR=0.0
Pod documented
162 10 my $id = shift;
163 10 return RDF::Trine::Node::Blank->new( $id );
164 }
165  
166 =item C<< literal ( $value, $lang, $dt ) >>
167  
168 Returns a L<RDF::Trine::Node::Literal> object with the given value and optional
169 language/datatype.
170  
171 =cut
172  
173 115 ▶sub literal {
Subroutine literal: called CC=1 SCAR=0.0
Pod documented
174 115 return RDF::Trine::Node::Literal->new( @_ );
175 }
176  
177 =item C<< variable ( $name ) >>
178  
179 Returns a L<RDF::Trine::Node::Variable> object with the given variable name.
180  
181 =cut
182  
183 3497 ▶sub variable {
Subroutine variable: called CC=1 SCAR=0.0
Pod documented
184 3497 my $name = shift;
185 3497 return RDF::Trine::Node::Variable->new( $name );
186 }
187  
188 =item C<< statement ( @nodes ) >>
189  
190 Returns a L<RDF::Trine::Statement> object with the supplied node objects.
191  
192 =cut
193  
194 46 ▶sub statement {
Subroutine statement: called CC=2 SCAR=6.9
Pod documented
195 46 my @nodes = @_;
196 46 ▶ if (scalar(@nodes) == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @nodes == 4) { } 23 23 46
197 23 return RDF::Trine::Statement::Quad->new( @nodes );
198 } else {
199 23 return RDF::Trine::Statement->new( @nodes );
200 }
201 }
202  
203 =item C<< store ( $config ) >>
204  
205 Returns a L<RDF::Trine::Store> object based on the supplied configuration string.
206  
207 =cut
208  
209 1 ▶sub store {
Subroutine store: called CC=1 SCAR=0.0
Pod documented
210 1 my $config = shift;
211 1 return RDF::Trine::Store->new_with_string( $config );
212 }
213  
214 =item C<< default_useragent ( [ $ua ] ) >>
215  
216 Returns the L<LWP::UserAgent> object used by default for any operation requiring network
217 requests. Ordinarily, the calling code will obtain the default user agent, and clone it
218 before further configuring it for a specific request, thus leaving the default object
219 untouched.
220  
221 If C<< $ua >> is passed as an argument, sets the global default user agent to this object.
222  
223 =cut
224  
225 68 { my $_useragent;
226 2 ▶sub default_useragent {
Subroutine default_useragent: called CC=3 SCAR=11.6
Pod documented
227 2 my $class = shift;
228 2 ▶ my $ua = shift || $_useragent;
Condition33%1/3
shift() || $_useragent
l!l&&r!l&&!r
002
MC/DC0%0/2
shift() || $_useragent
shift() $_useragent
Truth table33%1/3
A || B
A= shift()B= $_useragent
ABresult
1X1
011
000
229 2 ▶ unless (defined($ua)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ua) 2 0 2
230 2 $ua = LWP::UserAgent->new( agent => "RDF::Trine/$RDF::Trine::VERSION" );
231 }
232 2 $_useragent = $ua;
233 2 return $ua;
234 }}
235  
236 68 1; # Magic true value required at end of module
237 __END__
« RDF/Trine/Node/Blank.pm ↑ Summary RDF/Trine/Parser/Turtle/Constants.pm »