.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.28) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{ . if \nF \{ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "RDF::TrineX::Functions 3pm" .TH RDF::TrineX::Functions 3pm "2014-09-10" "perl v5.20.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" RDF::TrineX::Functions \- some shortcut functions for RDF::Trine's object\-oriented interface .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use RDF::TrineX::Functions \-all; \& \& my $model = model(); \& parse(\*(Aq/tmp/mydata.rdf\*(Aq, into => $model); \& \& $model\->add_statement(statement( \& iri(\*(Aqhttp://example.com/\*(Aq), \& iri(\*(Aqhttp://purl.org/dc/terms/title\*(Aq), \& "An Example", \& )); \& \& print RDF::Trine::Serializer \& \-> new(\*(AqTurtle\*(Aq) \& \-> serialize_model_to_string($model); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This is a replacement for the venerable RDF::TrineShortcuts. Not a drop-in replacement. It has fewer features, fewer dependencies, less hackishness, less magic and fewer places it can go wrong. .PP It uses Sub::Exporter, which allows exported functions to be renamed easily: .PP .Vb 2 \& use RDF::TrineX::Functions \& parse => { \-as => \*(Aqparse_rdf\*(Aq }; .Ve .SS "Functions" .IX Subsection "Functions" .ie n .IP """iri"", ""literal"", ""blank"", ""variable""" 4 .el .IP "\f(CWiri\fR, \f(CWliteral\fR, \f(CWblank\fR, \f(CWvariable\fR" 4 .IX Item "iri, literal, blank, variable" As per the similarly named functions exported by RDF::Trine itself. .Sp These are wrapped with a very tiny bit of DWIMmery. A blessed \s-1URI\s0 object passed to \f(CW\*(C`iri\*(C'\fR will be handled properly; a blessed \s-1URI\s0 object passed to \f(CW\*(C`literal\*(C'\fR will default the datatype to xsd:anyURI. A string starting with \*(L"_:\*(R" passed to either \f(CW\*(C`iri\*(C'\fR or \f(CW\*(C`blank\*(C'\fR will correctly create a blank node. A string starting with \*(L"?\*(R" passed to either \f(CW\*(C`blank\*(C'\fR or \f(CW\*(C`variable\*(C'\fR will correctly create a variable. If any of them are passed an existing RDF::Trine::Node, it will be passed through untouched. .Sp Other than that, no magic. .ie n .IP """curie""" 4 .el .IP "\f(CWcurie\fR" 4 .IX Item "curie" Like \f(CW\*(C`iri\*(C'\fR but passes strings through RDF::NS::Trine. .ie n .IP """statement(@nodes)""" 4 .el .IP "\f(CWstatement(@nodes)\fR" 4 .IX Item "statement(@nodes)" As per the similarly named function exported by RDF::Trine itself. .Sp Again, a tiny bit of DWIMmery: blessed \s-1URI\s0 objects are passed through \&\f(CW\*(C`iri\*(C'\fR and unblessed scalars (i.e. strings) are assumed to be literals. .ie n .IP """store""" 4 .el .IP "\f(CWstore\fR" 4 .IX Item "store" As per the similarly named function exported by RDF::Trine itself. .ie n .IP """model""" 4 .el .IP "\f(CWmodel\fR" 4 .IX Item "model" Returns a new RDF::Trine::Model. May be passed a store as a parameter. .ie n .IP """parse($source, %options)""" 4 .el .IP "\f(CWparse($source, %options)\fR" 4 .IX Item "parse($source, %options)" Parses the source and returns an RDF::Trine::Model. The source may be: .RS 4 .IP "\(bu" 4 a \s-1URI\s0 .Sp A string \s-1URI,\s0 blessed \s-1URI\s0 object or RDF::Trine::Node::Resource, which will be retrieved and parsed. .IP "\(bu" 4 a file .Sp A filehandle, Path::Class::File, IO::All, IO::Handle object, or the name of an existing file (i.e. a scalar string). The file will be read and parsed. .Sp Except in the case of Path::Class::File, IO::All and strings, you need to tell the \f(CW\*(C`parse\*(C'\fR function what parser to use, and what base \s-1URI\s0 to use. .IP "\(bu" 4 a string .Sp You need to tell the \f(CW\*(C`parse\*(C'\fR function what parser to use, and what base \s-1URI\s0 to use. .IP "\(bu" 4 a model or store .Sp An existing model or store, which will just be returned as-is. .IP "\(bu" 4 undef .Sp Returns an empty model. .RE .RS 4 .Sp The \f(CW\*(C`parser\*(C'\fR option can be used to provide a blessed RDF::Trine::Parser object to use; the \f(CW\*(C`type\*(C'\fR option can be used instead to provide a media type hint. The \f(CW\*(C`base\*(C'\fR option provides the base \s-1URI.\s0 The \f(CW\*(C`model\*(C'\fR option can be used to tell this function to parse into an existing model rather than returning a new one. The \f(CW\*(C`graph\*(C'\fR option may be used to provide a graph \&\s-1URI.\s0 .Sp \&\f(CW\*(C`into\*(C'\fR is an alias for \f(CW\*(C`model\*(C'\fR; \f(CW\*(C`type\*(C'\fR, \f(CW\*(C`using\*(C'\fR and \f(CW\*(C`as\*(C'\fR are aliases for \f(CW\*(C`parser\*(C'\fR; \f(CW\*(C`context\*(C'\fR is an alias for \f(CW\*(C`graph\*(C'\fR. .Sp Examples: .Sp .Vb 1 \& my $model = parse(\*(Aq/tmp/data.ttl\*(Aq, as => \*(AqTurtle\*(Aq); \& \& my $data = iri(\*(Aqhttp://example.com/data.nt\*(Aq); \& my $parser = RDF::Trine::Parser::NTriples\->new; \& my $model = model(); \& \& parse($data, using => $parser, into => $model); .Ve .RE .ie n .IP """serialize($data, %options)""" 4 .el .IP "\f(CWserialize($data, %options)\fR" 4 .IX Item "serialize($data, %options)" Serializes the data (which can be an RDF::Trine::Model or an RDF::Trine::Iterator) and returns it as a string. .Sp The \f(CW\*(C`serializer\*(C'\fR option can be used to provide a blessed RDF::Trine::Serializer object to use; the \f(CW\*(C`type\*(C'\fR option can be used instead to provide a type hint. The \f(CW\*(C`output\*(C'\fR option can be used to provide a filehandle, IO::All, Path::Class::File or file name to write to instead of returning the results as a string. .Sp \&\f(CW\*(C`to\*(C'\fR and \f(CW\*(C`file\*(C'\fR are aliases for \f(CW\*(C`output\*(C'\fR; \f(CW\*(C`type\*(C'\fR, \f(CW\*(C`using\*(C'\fR and \f(CW\*(C`as\*(C'\fR are aliases for \f(CW\*(C`serializer\*(C'\fR. .Sp Examples: .Sp .Vb 1 \& print serialize($model, as => \*(AqTurtle\*(Aq); \& \& my $file = Path::Class::File\->new(\*(Aq/tmp/data.nt\*(Aq); \& serialize($iterator, to => $file, as => \*(AqNTriples\*(Aq); .Ve .SS "Array References" .IX Subsection "Array References" In addition to the above interface, each function supports being called with a single arrayref argument. In those cases, the arrayref is dereferenced into an array, and treated as a list of arguments. That is, the following are equivalent: .PP .Vb 2 \& foo($bar, $baz); \& foo([$bar, $baz]); .Ve .PP This is handy if you're writing a module of your own and wish to accept some \&\s-1RDF\s0 data: .PP .Vb 3 \& sub my_method { \& my ($self, $rdf, $foo) = @_; \& $rdf = parse($rdf); \& \& .... \& } .Ve .PP Your method can now be called like this: .PP .Vb 1 \& $object\->my_method($model, \*(Aqfoo\*(Aq); \& \& $object\->my_method($url, \*(Aqfoo\*(Aq); \& \& $object\->my_method( \& [ $filehandle, as => \*(AqTurtle\*(Aq, base => $uri ], \& \*(Aqfoo\*(Aq, \& ); .Ve .SS "Export" .IX Subsection "Export" By default, nothing is exported. You need to request things: .PP .Vb 1 \& use RDF::TrineX::Functions qw< iri literal blank statement model >; .Ve .PP Thanks to Sub::Exporter, you can rename functions: .PP .Vb 4 \& use RDF::TrineX::Functions \& qw< literal statement model >, \& blank => { \-as => \*(Aqbnode\*(Aq }, \& iri => { \-as => \*(Aqresource\*(Aq }; .Ve .PP If you want to export everything, you can do: .PP .Vb 1 \& use RDF::TrineX::Functions \-all; .Ve .PP To export just the functions which generate RDF::Trine::Node objects: .PP .Vb 1 \& use RDF::TrineX::Functions \-nodes; .Ve .PP Or maybe even: .PP .Vb 1 \& use RDF::TrineX::Functions \-nodes => { \-suffix => \*(Aq_node\*(Aq }; .Ve .PP If you want to export something roughly compatible with the old RDF::TrineShortcuts, then there's: .PP .Vb 1 \& use RDF::TrineX::Functions \-shortcuts; .Ve .PP When exporting the \f(CW\*(C`serialize\*(C'\fR function you may set a default format: .PP .Vb 2 \& use RDF::TrineX::Functions \& serialize => { \-type => \*(AqNTriples\*(Aq }; .Ve .PP This will be used when \f(CW\*(C`serialize\*(C'\fR is called with no explicit type given. .SS "Pseudo-OO interface" .IX Subsection "Pseudo-OO interface" .ie n .IP """new""" 4 .el .IP "\f(CWnew\fR" 4 .IX Item "new" This acts as a constructor, returning a new RDF::TrineX::Functions object. .PP All the normal functions can be called as methods: .PP .Vb 2 \& my $R = RDF::TrineX::Functions\->new; \& my $model = $R\->model; .Ve .PP There's no real advantage to using this module as an object, but it can help you avoid namespace pollution. .SH "BUGS" .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" RDF::Trine, RDF::QueryX::Lazy, \s-1RDF::NS\s0. .SH "AUTHOR" .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2012 by Toby Inkster. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "DISCLAIMER OF WARRANTIES" .IX Header "DISCLAIMER OF WARRANTIES" \&\s-1THIS PACKAGE IS PROVIDED \*(L"AS IS\*(R" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\s0