package Xot; use strict; use XML::Twig; use Xot::Table; sub new { my $class = shift; my $self = bless {}, $class; $self->init(@_); return $self; } sub init { my $self = shift; my $file = shift; $self->{TWIG} = XML::Twig->new( twig_handlers => { 'table' => sub { $self->add_table($_) }, }, pretty_print => 'indented' ); if (defined $file) { $self->file($file); $self->twig->parsefile($file); } } sub file { my $self = shift; my $file = shift; $self->{FILE} = $file if defined $file; return $self->{FILE}; } sub twig { my $self = shift; return $self->{TWIG} } sub table { my $self = shift; my $name = shift; my $table = shift; die "must call table with a table name" unless $name; $self->{TABLES}->{$name} = $table if defined $table; return $self->{TABLES}->{$name} } sub tables { my $self = shift; return keys %{ $self->{TABLES} || {} }; } sub add_table { my $self = shift; my $twig = shift; die "must call add_table with a twig" unless defined $twig; my $name = $twig->att("name"); my $table = Xot::Table->new($twig); $self->table($name => $table); } 1;