diff options
author | dakkar <dakkar@thenautilus.net> | 2009-04-25 11:50:12 +0200 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2009-04-25 11:50:12 +0200 |
commit | 4ffb754e0096becf49aab9a6a8ba358d4b347ef2 (patch) | |
tree | cc6b160af8f36f411e7f077e36395e958eaccd50 /lib/Tree/Template/Declare.pm | |
parent | passes critic, but changes for "attach_nodes" are wrong (diff) | |
download | Tree-Template-Declare-4ffb754e0096becf49aab9a6a8ba358d4b347ef2.tar.gz Tree-Template-Declare-4ffb754e0096becf49aab9a6a8ba358d4b347ef2.tar.bz2 Tree-Template-Declare-4ffb754e0096becf49aab9a6a8ba358d4b347ef2.zip |
fixed "attach_nodes" tests, documented it
Diffstat (limited to 'lib/Tree/Template/Declare.pm')
-rw-r--r-- | lib/Tree/Template/Declare.pm | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/Tree/Template/Declare.pm b/lib/Tree/Template/Declare.pm index 38f933c..151801a 100644 --- a/lib/Tree/Template/Declare.pm +++ b/lib/Tree/Template/Declare.pm @@ -64,7 +64,8 @@ sub _build_group { local $current_node[0]=$node; $_[0]->(caller_args(1)); } - if ($current_node[0] && !defined wantarray) { + my $scalar_context=defined wantarray && !wantarray; + if ($current_node[0] && !$scalar_context) { $builder->add_child_node($current_node[0],$node); } return $node; @@ -86,6 +87,7 @@ sub _build_group { $builder->set_node_attributes($current_node[0],\%attrs); return; }, + detached => sub($) { return scalar $_[0] }, }; if ($builder->can('_munge_exports')) { return $builder->_munge_exports($normal_exports,\@current_node); @@ -137,11 +139,26 @@ Uses the builder's C<new_tree> and C<finalize_tree>. =head2 C<node> This function takes a code ref or a block, inside which calls to -C<name>, C<attribs>, and C<node> should be made, and adds the node to -the "calling" node or tree. It also returns the node. +C<name>, C<attribs>, and C<node> should be made, and returns the node. + +If I<not> called in scalar context, it also adds the node to the +"calling" node or tree. Uses the builder's C<new_node> and C<add_child_node>. +=head2 C<detached> + +Alias for C<scalar>, so that you can say C<return detached node ...> +without having to worry about the calling context. + +=head2 C<attach_nodes> + +This function takes a list of nodes, and adds them (in order) to the +"calling" node or tree. You should only use this with nodes you +obtained by calling C<node> in scalar context. + +Uses the builder's C<add_child_node>. + =head2 C<name> This function takes a scalar, and sets the name of the current node to |