James A. Duncan
and 1 contributors

NAME

XML::DOMBacked - objects backed by a DOM

SYNOPSIS

  package Person;

  use base 'XML::DOMBacked';

  Person->uses_namespace(
                         'foaf' => 'http://xmlns.com/foaf/0.1/',
                         'rdf'  => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
                        );
  Person->has_properties( 'foaf:name','foaf:title','foaf:nick' );
  Person->has_attributes( 'rdf:nodeID' );
  Person->has_a( 'Person::Knows' );

  sub nodename { "foaf:Person" }

  package Person::Knows;

  use base 'XML::DOMBacked';

  Person::Knows->has_many( people => { class => 'Person' } );

  package main;

  my $p = Person->new;
  $p->nodeID("me");
  $p->name('A. N. Other');
  $p->title('Mr');
  $p->nick('another');

  my $a = Person->new;
  $a->name('Yet Another');

  $p->Knows->add_Person( $a );
  print $p->as_xml;

  $p = Person->from_uri( 'file:person.xml' );

DESCRIPTION

The XML::DOMBacked class lets you back an object on an XML DOM. Think of it as Class::DBI for XML files. You can specifiy things you want to be properties (nodes), attributes, and other objects. XML::DOMBacked takes care of the heavy lifting so that you don't have to.

CONSTRUCTORS

new()

Constructs a new object.

from_uri()

Loads an object from a URI. Expects XML at the other end.

METHODS

uses_namespace( prefix => uri )

Adds an XML namespace to the object.

has_properties( ARRAY )

Adds XML Elements to the object. These become accessors.

has_attributes( ARRAY )

Adds XML Attributes to the object. These become accessors.

has_a( ARRAY )

Adds 1..1 relationships with other classes to the object. The other classes must also inherit from XML::DOMBacked.

has_many( PLURAL => SINGULAR )

Adds add_SINGULAR, remove_SINGLUAR and PLURAL methods to the class.

has_many( PLURAL => { class => CLASS } )

Looks up the NODENAME for the class, then creates add_NODENAME, remove_NODENAME, and PLURAL methods to the class.

BUGS

Probably loads. This is really funky, crazy code. I'd be surprised if there aren't bugs.

AUTHOR

James A. Duncan <jduncan@fotango.com>

COPYRIGHT

Copyright 2005 Fotango Ltd. All Rights Reserved.