File Coverage

blib/lib/RDF/Trine.pm
Criterion Covered Total %
statement 95 95 100.0
branch 6 8 75.0
condition 1 3 33.3
subroutine 31 31 100.0
pod 7 7 100.0
total 140 144 97.2


line stmt bran cond sub pod time code
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.018
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     68   1333876 use 5.010;
  68         242  
83 68     68   337 use strict;
  68         124  
  68         1162  
84 68     68   284 use warnings;
  68         130  
  68         1648  
85 68     68   318 no warnings 'redefine';
  68         124  
  68         2187  
86 68     68   29659 use Module::Load::Conditional qw[can_load];
  68         1402255  
  68         3807  
87 68     68   40137 use LWP::UserAgent;
  68         2359888  
  68         7091  
88              
89             our ($debug, @ISA, $VERSION, @EXPORT_OK);
90             BEGIN {
91 68     68   293 $debug = 0;
92 68         156 $VERSION = '1.018';
93            
94 68         502 require Exporter;
95 68         680 @ISA = qw(Exporter);
96 68         223 @EXPORT_OK = qw(iri blank literal variable statement store UNION_GRAPH NIL_GRAPH);
97            
98 68 50       377 unless ($ENV{RDFTRINE_NO_REDLAND}) {
99 68         502 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     68   423547 use constant UNION_GRAPH => 'tag:gwilliams@cpan.org,2010-01-01:RT:ALL';
  68         160  
  68         4131  
108 68     68   401 use constant NIL_GRAPH => 'tag:gwilliams@cpan.org,2010-01-01:RT:NIL';
  68         139  
  68         3132  
109              
110 68     68   45241 use Log::Log4perl qw(:easy);
  68         2320650  
  68         365  
111             if (! Log::Log4perl::initialized() ) {
112             Log::Log4perl->easy_init($ERROR);
113             }
114              
115 68     68   76828 use RDF::Trine::Graph;
  68         221  
  68         2168  
116 68     68   28988 use RDF::Trine::Parser;
  68         252  
  68         2301  
117 68     68   541 use RDF::Trine::Serializer;
  68         152  
  68         1573  
118 68     68   359 use RDF::Trine::Node;
  68         144  
  68         2426  
119 68     68   376 use RDF::Trine::Statement;
  68         145  
  68         1010  
120 68     68   306 use RDF::Trine::Namespace;
  68         235  
  68         461  
121 68     68   25612 use RDF::Trine::NamespaceMap;
  68         199  
  68         1858  
122 68     68   446 use RDF::Trine::Iterator;
  68         149  
  68         2377  
123 68     68   362 use RDF::Trine::Store;
  68         153  
  68         1225  
124 68     68   307 use RDF::Trine::Error;
  68         137  
  68         395  
125 68     68   29591 use RDF::Trine::Model;
  68         216  
  68         1880  
126              
127 68     68   29940 use RDF::Trine::Parser::Turtle;
  68         323  
  68         2928  
128 68     68   33134 use RDF::Trine::Parser::TriG;
  68         208  
  68         18064  
129              
130              
131             sub _uniq {
132 762     762   1527 my %seen;
133             my @data;
134 762         1718 foreach (@_) {
135 2045 100       6489 push(@data, $_) unless ($seen{ $_ }++);
136             }
137 762         4267 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             sub iri {
151 114     114 1 1974 my $iri = shift;
152 114         498 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             sub blank {
162 10     10 1 38 my $id = shift;
163 10         58 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             sub literal {
174 115     115 1 2077 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             sub variable {
184 3497     3497 1 8888 my $name = shift;
185 3497         9694 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             sub statement {
195 46     46 1 125 my @nodes = @_;
196 46 100       136 if (scalar(@nodes) == 4) {
197 23         107 return RDF::Trine::Statement::Quad->new( @nodes );
198             } else {
199 23         92 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             sub store {
210 1     1 1 7 my $config = shift;
211 1         10 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             { my $_useragent;
226             sub default_useragent {
227 2     2 1 6 my $class = shift;
228 2   33     13 my $ua = shift || $_useragent;
229 2 50       8 unless (defined($ua)) {
230 2         23 $ua = LWP::UserAgent->new( agent => "RDF::Trine/$RDF::Trine::VERSION" );
231             }
232 2         4862 $_useragent = $ua;
233 2         13 return $ua;
234             }}
235              
236             1; # Magic true value required at end of module
237             __END__
238              
239             =back
240              
241             =head1 BUGS
242              
243             Please report any bugs or feature requests to through the GitHub web interface
244             at L<https://github.com/kasei/perlrdf/issues>.
245              
246             =head1 SEE ALSO
247              
248             L<http://www.perlrdf.org/>
249              
250             =head1 AUTHOR
251              
252             Gregory Todd Williams C<< <gwilliams@cpan.org> >>
253              
254             =head1 COPYRIGHT
255              
256             Copyright (c) 2006-2012 Gregory Todd Williams. This
257             program is free software; you can redistribute it and/or modify it under
258             the same terms as Perl itself.
259              
260             =cut