NAME

RDF::Pool -- RDF (XML) (de)serialization of Perl objects

SYNOPSIS

    use RDF::Pool;
    my $pool = RDF::Pool->new("http://sample.com/cars#";);
    $pool->add_prefix_table_entry("_color_", "http://sample.com/color#";);
    my $car = bless { make=>"Honda", model=>"Civic" }, Car;
    $car->{color} = bless { _color_name=>"Light Blue" }, _color_Color;
    $pool->add($car);
    $pool->load_rdfxml_file("somefile.rdf");
    $pool->save_rdfxml_file("somefile.rdf", lock=>1, append=>1);
    ... produces:
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
             xmlns:color="http://sample.com/color#";
             xmlns="http://sample.com/cars#";>
      <Car rdf:about="#obj0">
        <make>Honda</make>
        <color>
          <color:Color rdf:about="#obj1">
            <color:name>Light Blue</color:name>
          </color:Color>
        </color>
        <model>Civic</model>
      </Car>
    </rdf:RDF>

BASIC CONCEPT

This package contains tools for loading and saving sets of Perl objects to RDF/XML files. The mapping is intended to be generally intuitive, so Perl programmers can use the data structures they want, while the RDF/XML is decent for use with other toolkits.

In general, a ``pool'' is a dynamic set of RDF Statements (a mutable RDF Graph). An RDF::Pool object lets you convert the information between the RDF/XML encoding and a natural encoding as Perl objects.

NAMESPACES AND PREFIXES

In RDF, objects and attributes are identified by strings conforming to the URI-Reference syntax. A set of names with a common prefix (usually ending in ``#'') are sometimes considered a namespace, because in the XML/RDF encoding, they can appear as XML namespaces. Here, were treated them simply as common prefixes; they are called ``rdf_prefix'' strings in the prefix table.

Similarly, in Perl, we assume that attributes may be grouped by common prefixes, which we call perl_prefix in the prefix table.

The two default entries in the table are these:

   perl_prefix    rdf_prefix
   ===========    ==========
    "_rdf_"        "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
    ""             "#" (unless set by the parameter to new())

This means the RDF ``type'' property, whose full RDF name is ``http://www.w3.org/1999/02/22-rdf-syntax-ns#type'' will be mapped to/from ``_rdf_type'' when used as a hash key on serialize objects.

The second entry in the table says that Perl keys not matching earlier entries in the table should be prefixed as given. This is essentially the default namespace.

MULTIPLE VALUES

Unlike Perl, RDF allows an object to have an attribute with multiple values.

      car >- near -> "house".
      car >- near -> "tree".

After reading data like this, we'll have

      $car->{near} = "house";
      $car->{@near} = [ "house", "tree" ];