package Tree::Template::Declare;
use strict;
use warnings;
use Sub::Exporter;
use Tree::DAG_Node::XPath;
our $VERSION='0.1';
Sub::Exporter::setup_exporter({
exports => [qw(tree node name attribs)],
groups => {
default => [qw(tree node name attribs)],
}
});
our $current_node;
sub tree(&) {
local $current_node=undef;
my ($ret)=$_[0]->();
return $ret;
}
sub node(&) {
my $node=Tree::DAG_Node::XPath->new();
{
local $current_node=$node;
$_[0]->();
}
if ($current_node) {
$current_node->add_daughter($node);
}
return $node;
}
sub name($) {
$current_node->name($_[0]);
}
sub attribs {
my %attrs=@_;
$current_node->attributes(\%attrs);
return;
}
1;