CPAN Upload: T/TO/TOBYINK/RDF-TrineShortcuts-0.100.tar.gz
Toby Inkster
mail at tobyinkster.co.uk
Wed Jun 23 16:12:20 CEST 2010
On Wed, 23 Jun 2010 14:17:21 +0200
PAUSE <upload at pause.perl.org> wrote:
> file: $CPAN/authors/id/T/TO/TOBYINK/RDF-TrineShortcuts-0.100.tar.gz
> size: 44641 bytes
> md5: a47be987e9cad6b3661d88a143449846
This now provides an object-oriented interface (disabled by default).
You enable it by passing a parameter "-methods" on the "use
RDF::TrineShortcuts" line.
use RDF::TrineShortcuts qw(-methods);
Via some symbol table manipulation, the above will cheekily polute
the "RDF::Trine" and "URI" namespaces with some shortcut methods. Let's
take a look...
use RDF::TrineShortcuts qw(:all -methods);
# Let's create a standard Trine model...
$model = RDF::Trine::Model->temporary_model;
# Let's add a triple...
$model->add_statement(rdf_statement(
'http://example.net/alice#me',
'foaf:name',
['Alice',lang=>'en']));
# And load some data via a shortcut method...
$model->parse(<<'DATA', base=>'http://example.net/');
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#bob> a foaf:Person ; foaf:name "Bob" .
DATA
# Print it out in Turtle...
print $model->string('turtle');
# Load some more data...
$model->parse('http://tobyinkster.co.uk/');
# Let's query it...
my $results = $model->sparql('SELECT * {?id foaf:name ?name}');
# Convert an Iterator of hashrefs of Nodes
# into a list of hashrefs of scalars...
my @results = $results->flatten;
foreach my $r (@results)
{
printf("<%s>: %s\n",
$r->{'id'},
$r->{'name'});
}
# We even extend URI...
my $endpoint = URI->new('http://tobyinkster.co.uk/_sparql');
my $results = $endpoint->sparql(
'SELECT * {?id foaf:name ?name}');
--
Toby A Inkster
<mailto:mail at tobyinkster.co.uk>
<http://tobyinkster.co.uk>
More information about the Dev
mailing list