From ca60f18e9906e84355287ac427f5f9e6e6b36b41 Mon Sep 17 00:00:00 2001 From: Gianni Ceccarelli Date: Tue, 21 Apr 2009 15:25:44 +0200 Subject: docs, and changed the export-munging methods for builders --- lib/Tree/Template/Declare/DAG_Node.pm | 28 ++++++++++++++++++ lib/Tree/Template/Declare/HTML_Element.pm | 48 +++++++++++++++++++++++++++++++ lib/Tree/Template/Declare/LibXML.pm | 31 ++++++++++++++++++-- 3 files changed, 105 insertions(+), 2 deletions(-) (limited to 'lib/Tree/Template/Declare') diff --git a/lib/Tree/Template/Declare/DAG_Node.pm b/lib/Tree/Template/Declare/DAG_Node.pm index 806413d..2736a5f 100644 --- a/lib/Tree/Template/Declare/DAG_Node.pm +++ b/lib/Tree/Template/Declare/DAG_Node.pm @@ -54,3 +54,31 @@ sub set_node_attributes { } 1; +__END__ + +=head1 NAME + +Tree::Template::Declare::DAG_Node + +=head1 SYNOPSIS + +See L. + +=head1 SPECIFICITIES + +This module will build trees using L. You can make it +use another module (assuming it has the same interface, for example +L) by passing the class name to the C +method. + + use Tree::Template::Declare builder => '+DAG_Node'; # default + + use Tree::Template::Declare builder => + Tree::Template::Declare::DAG_Node->new('Tree::DAG_Node::XPath'); + # custom class + +=head1 AUTHOR + +Gianni Ceccarelli + +=cut diff --git a/lib/Tree/Template/Declare/HTML_Element.pm b/lib/Tree/Template/Declare/HTML_Element.pm index 1480987..c2dd87c 100644 --- a/lib/Tree/Template/Declare/HTML_Element.pm +++ b/lib/Tree/Template/Declare/HTML_Element.pm @@ -10,6 +10,21 @@ sub new { return bless {},$class; } +sub _munge_exports { + my ($self,$exports)=@_; + + return { + %$exports, + text_node => sub($) { + $exports->{node}->( + sub { + $exports->{name}->('~text'); + $exports->{attribs}->(text => $_[0]); + }); + }, + }; +} + sub new_tree { my ($self)=@_; @@ -57,3 +72,36 @@ sub set_node_attributes { } 1; +__END__ + +=head1 NAME + +Tree::Template::Declare::HTML_Element + +=head1 SYNOPSIS + +See L. + +=head1 SPECIFICITIES + +This module will build trees using L. + +To create text nodes, you would be forced to say: + + node { + name '~text'; + attribs text => 'some text'; + } + +which is too cumbersone. You can instead use: + + text_node 'some text'; + +HTML::Element's C method will be called by +C before returning the tree object. + +=head1 AUTHOR + +Gianni Ceccarelli + +=cut diff --git a/lib/Tree/Template/Declare/LibXML.pm b/lib/Tree/Template/Declare/LibXML.pm index f8c0e01..d5e208c 100644 --- a/lib/Tree/Template/Declare/LibXML.pm +++ b/lib/Tree/Template/Declare/LibXML.pm @@ -10,10 +10,11 @@ sub new { return bless {ns=>{':default'=>undef}},$class; } -sub _additional_exports { - my ($self)=@_; +sub _munge_exports { + my ($self,$exports)=@_; return { + %$exports, xmlns => sub($$) { $self->{ns}->{$_[0]}=$_[1]; return; @@ -95,3 +96,29 @@ sub set_node_attributes { } 1; +__END__ + +=head1 NAME + +Tree::Template::Declare::LibXML + +=head1 SYNOPSIS + +See L. + +=head1 SPECIFICITIES + +A function C is exported, so that you can declare XML namespaces: + + xmlns test => 'http://test/'; + + node { name 'test:elem'; attribs id => 1, 'test:attr' => 5 }; + +You I create nodes with qualified names with undeclared prefixes, +but it's probably not a good idea. + +=head1 AUTHOR + +Gianni Ceccarelli + +=cut -- cgit v1.2.3