POE::XUL::RDF - RDF builder class
use POE::XUL::RDF; my $data = [ 'RDF:about' => "all-animals", { name => 'Lion', species => 'Panthera leo', class => 'Mammal', 'RDF:about' => "mammals/lion" }, { name => 'Tarantula', species => 'Avicularia avicularia', class => 'Arachnid', 'RDF:about' => "arachnids/tarantula" }, { name => 'Hippopotamus', species => 'Hippopotamus amphibius', class => 'Mammal', 'RDF:about' => 'mammals/hippopotamus' } ]; my $rdf = POE::XUL::RDF->new( baseref => "http://some-url.com" ); $rdf->baserdf( 'rdf' ); $rdf->data( $data ); my $tree = Tree( datasources => $rdf, ref => $ref->dataref # ... );
Primitive RDF generation for XUL trees.
my $rdf = POE::XUL::RDF->new( %params );
Creates a new object. %params may contain "NS", "baseref", "baserdf", "dataref" or "data".
%params
Namespace of the XML tags your data tuples will live in.
$rdf->baseref( $url ); $url = $rdf->baseref;
Get or set the base URL used to create "baserdf", "dataref" and "about".
$rdf->baserdf( $url ); $url = $rdf->baserdf;
Get or set the base URL of the data. Defaults to 'rdf' under "baseref".
$rdf->baserdf( $url ); $tree->setAttribute( ref => $rdf->dataref );
Get or set the URL of the main data sequence. Can also be set if you have an "RDF:about" in your data.
$rdf->data( $AoH ); $AoH = $rdf->data;
Get or set the data contained in the RDF. POE::XUL::RDF only implements a simplified data format. $AoH must be an arrayref of hashrefs. The top arrayref is a RDF:Seq. Each hashref is an RDF:li. Keys are the XML tags in the "NS" namespace. Values are text nodes. If a key name begins with 'RDF:' it is placed as an attribute of the RDF:Description.
$AoH
RDF:Seq
RDF:li
RDF:Description
Example:
[ { city=>"Montreal", TZ=>"+5", 'RDF:note' => 'Something' }, { city=>"Cochabamba", TZ=>"+4" } ]
Becomes roughly
<RDF:Seq> <RDF:li><RDF:Description note="Something"> <NS:city>Montreal</NS:city> <NS:TZ>+5</NS:TZ> </RDF:Description></RDF:li> <RDF:li><RDF:Description> <NS:city>Cochabamba</NS:city> <NS:TZ>+4</NS:TZ> </RDF:Description></RDF:li> </RDF:Seq>
RDF:about is a special attribute. Is is converted into an absolute URL with "baseref".
What's more, if the first element in "data" is the string 'RDF:about', the second element is used as the about attribute of the main RDF:Seq.
about
$rdf->baseref( 'http://example.com' ); $rdf->data( [ 'RDF:about' => 'some-cities', { city=>"Montreal", TZ=>"+5", 'RDF:about' => 'canada/mtl' }, ] );
Becomes roughly:
<RDF:Seq about="http://example.com/some-cities> <RDF:li><RDF:Description about="http://example.com/canada/mtl> <NS:city>Montreal</NS:city> <NS:TZ>+5</NS:TZ> </RDF:Description></RDF:li> </RDF:Seq>
my $frag = $rdf->fragment( $name );
Builds an URL that references $name fragment of the current RDF.
my $frag = $rdf->rdf_fragment( $name );
Builds an rdf: URL that references $name fragment of the current RDF. Useful for setting the sort attribute of a TreeCol, for example
TreeCol( id=>'TZ', sort=>$rdf->rdf_fragment( 'TZ' ) );
The following 3 methods are used to interface with the ChangeManager. You might want to overload them if you wish to define a new type of datasource. For example, a DBI datasource.
my $xml = $rdf->as_xml;
Convert the RDF to an XML string.
$resp->content_type( $rdf->mime_type );
Returns the MIME-type of the RDF. Defaults to 'application/rdf+xml'.
my $row = $rdf->index_of( $col, $value );
Search the the first tupple that has the $col column set to $value. This is needed because if the user has sorted the data in the browser, the Select event's selectedIndex will reference the row as seen on the screen, not the row as present in the dataset.
selectedIndex
POE::XUL::Node
Philip Gwyn <gwyn-at-cpan.org>
Copyright 2008-2010 by Philip Gwyn. All rights reserved;
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install POE::XUL::RDF, copy and paste the appropriate command in to your terminal.
cpanm
cpanm POE::XUL::RDF
CPAN shell
perl -MCPAN -e shell install POE::XUL::RDF
For more information on module installation, please visit the detailed CPAN module installation guide.