NAME

POE::XUL::RDF - RDF builder class

SYNOPSIS

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
                 # ...
               );

DESCRIPTION

Primitive RDF generation for XUL trees.

METHODS

new

my $rdf = POE::XUL::RDF->new( %params );

Creates a new object. %params may contain "NS", "baseref", "baserdf", "dataref" or "data".

NS

Namespace of the XML tags your data tuples will live in.

baseref

$rdf->baseref( $url );
$url = $rdf->baseref;

Get or set the base URL used to create "baserdf", "dataref" and "about".

baserdf

$rdf->baserdf( $url );
$url = $rdf->baserdf;

Get or set the base URL of the data. Defaults to 'rdf' under "baseref".

dataref

$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.

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.

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

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.

Example:

$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>

fragment

my $frag = $rdf->fragment( $name );

Builds an URL that references $name fragment of the current RDF.

rdf_fragment

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' ) );

DATASOURCES INTERFACE

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.

as_xml

my $xml = $rdf->as_xml;

Convert the RDF to an XML string.

mime_type

$resp->content_type( $rdf->mime_type );

Returns the MIME-type of the RDF. Defaults to 'application/rdf+xml'.

index_of

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.

SEE ALSO

POE::XUL::Node

AUTHOR

Philip Gwyn <gwyn-at-cpan.org>

COPYRIGHT AND LICENSE

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.