summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGianni Ceccarelli <dakkar@dechirico.(none)>2009-04-21 15:50:39 +0200
committerGianni Ceccarelli <dakkar@dechirico.(none)>2009-04-21 15:50:39 +0200
commit6ab176ee34c6b0b7e2e1e85dde5bafcd76cb7e93 (patch)
tree77f51432877d1f316eb65caeea122063627ab6f3 /lib
parentdocs, and changed the export-munging methods for builders (diff)
downloadTree-Template-Declare-6ab176ee34c6b0b7e2e1e85dde5bafcd76cb7e93.tar.gz
Tree-Template-Declare-6ab176ee34c6b0b7e2e1e85dde5bafcd76cb7e93.tar.bz2
Tree-Template-Declare-6ab176ee34c6b0b7e2e1e85dde5bafcd76cb7e93.zip
added text nodes to XML
Diffstat (limited to 'lib')
-rw-r--r--lib/Tree/Template/Declare.pm24
-rw-r--r--lib/Tree/Template/Declare/LibXML.pm19
2 files changed, 37 insertions, 6 deletions
diff --git a/lib/Tree/Template/Declare.pm b/lib/Tree/Template/Declare.pm
index 1c4a53a..118fcea 100644
--- a/lib/Tree/Template/Declare.pm
+++ b/lib/Tree/Template/Declare.pm
@@ -80,7 +80,7 @@ sub _build_group {
},
};
if ($builder->can('_munge_exports')) {
- return $builder->_munge_exports($normal_exports);
+ return $builder->_munge_exports($normal_exports,\@current_node);
}
else {
return $normal_exports;
@@ -207,10 +207,24 @@ adds the second node at the end of the children list of the first node
=back
The builder can also implement an C<_munge_exports> method. If it
-does, C<_munge_exports> will be called with a hash ref consisting of
-the methods that C<Tree::Template::Declare> wants to export, and it
-should return a hash ref with the methods that will actually be
-exported.
+does, C<_munge_exports> will be called with:
+
+=over 4
+
+=item *
+
+a hash ref consisting of the functions that C<Tree::Template::Declare>
+wants to export,
+
+=item *
+
+an array ref, whose first element will be the current node whenever
+the user calls an exported function
+
+=back
+
+C<_munge_exports> should return a hash ref with the functions that
+will actually be exported.
See L<Sub::Exporter>, in particular the section on group builders, for
details. See L<Tree::Template::Declare::HTML_Element> and
diff --git a/lib/Tree/Template/Declare/LibXML.pm b/lib/Tree/Template/Declare/LibXML.pm
index d5e208c..066d2e4 100644
--- a/lib/Tree/Template/Declare/LibXML.pm
+++ b/lib/Tree/Template/Declare/LibXML.pm
@@ -11,7 +11,7 @@ sub new {
}
sub _munge_exports {
- my ($self,$exports)=@_;
+ my ($self,$exports,$current_node_aref)=@_;
return {
%$exports,
@@ -19,6 +19,11 @@ sub _munge_exports {
$self->{ns}->{$_[0]}=$_[1];
return;
},
+ text_node => sub($) {
+ if ($current_node_aref->[0]) {
+ $current_node_aref->[0]->appendTextNode($_[0]);
+ },
+ },
};
}
@@ -117,6 +122,18 @@ A function C<xmlns> is exported, so that you can declare XML namespaces:
You I<can> create nodes with qualified names with undeclared prefixes,
but it's probably not a good idea.
+To add text nodes, you could do something like:
+
+ my $el=node { name 'elem_with_text' };
+ $el->appendTextNode('some text content');
+
+This is ugly, so you can do:
+
+ node {
+ name 'elem_with_text';
+ text_node 'some text content';
+ };
+
=head1 AUTHOR
Gianni Ceccarelli <dakkar@thenautilus.net>