Decl::Semantics::Repeat - implements a repeated node
Version 0.01
The "repeat" node repeats its children at its own hierarchical level. It's essentially a loop at build time, a quick way to build structure based on data retrieved. The foreach/select nodes are convenient abbreviations for the long-form repeat. Whereas the repeat node has separate children for its query and repetition text and thus has a place to put parameters, code, and other things to refine the repetition process, the foreach/select nodes just treat their lines as SQL/data queries directly for brevity's sake.
foreach
select
repeat
Called by Decl::Semantics during import, to find out what xmlapi tags this plugin claims to implement.
The select/foreach node is the first to parse its line differently from the standard. It treats its entire line as an SQL query (or a data query, depending) - it uses the same syntax as the ^foreach/^select command in embedded Perl.
The only exception is that to make the expression of the body easier, it always uses fetchrow_hashref to retrieve the values from each row. The hash keys are then used to determine what should be replaced in the body for each child built.
fetchrow_hashref
Same thing. The select/foreach node doesn't want to parse its body. Normally, we'd just mark that in build_handlers, but if we do that, we can't macroinsert the results (because there wouldn't be any body parser there, either... Yes, this was a confusing couple of hours.)
Here is where we actually do the work of instantiating our true children, based on the body given us and repeating over the results of the query passed in. The repeat body is either the direct body of this tag, or the body of the "text" tag below it, depending on whether this is a "repeat" or a "foreach"/"select" construct.
Finally, at runtime, we just execute by calling each of our macroinserted children. Et voila!
We override nodes to permit group shenanigans.
nodes
Michael Roberts, <michael at vivtek.com>
<michael at vivtek.com>
Please report any bugs or feature requests to bug-decl at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Decl. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-decl at rt.cpan.org
Copyright 2010 Michael Roberts.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Decl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Decl
CPAN shell
perl -MCPAN -e shell install Decl
For more information on module installation, please visit the detailed CPAN module installation guide.