Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For <a href="http://search.cpan.org" rel="nofollow noreferrer">CPAN</a> offerings have a look at the following (in alphabetical order)...</p> <ul> <li><a href="http://search.cpan.org/dist/Builder/" rel="nofollow noreferrer">Builder</a></li> <li><a href="http://search.cpan.org/dist/HTML-Tree/lib/HTML/AsSubs.pm" rel="nofollow noreferrer">HTML::AsSubs</a></li> <li><a href="http://search.cpan.org/dist/HTML-Tiny/" rel="nofollow noreferrer">HTML::Tiny</a></li> <li><a href="http://search.cpan.org/dist/Markapl/" rel="nofollow noreferrer">Markapl</a></li> <li><a href="http://search.cpan.org/dist/Template-Declare/" rel="nofollow noreferrer">Template::Declare</a></li> <li><a href="http://search.cpan.org/dist/XML-Generator/" rel="nofollow noreferrer">XML::Generator</a></li> </ul> <p>Using the table part of the CL-WHO example provided (minus Roman numerals and s/background-color/color/ to squeeze code into screen width here!)....</p> <p><br /></p> <h2>Builder</h2> <pre><code>use Builder; my $builder = Builder-&gt;new; my $h = $builder-&gt;block( 'Builder::XML' ); $h-&gt;table( { border =&gt; 0, cellpadding =&gt; 4 }, sub { for ( my $i = 1; $i &lt; 25; $i += 5 ) { $h-&gt;tr( { align =&gt; 'right' }, sub { for my $j (0..4) { $h-&gt;td( { color =&gt; $j % 2 ? 'pink' : 'green' }, $i + $j ); } }); } }); say $builder-&gt;render; </code></pre> <p><br /></p> <h2>HTML::AsSubs</h2> <pre><code>use HTML::AsSubs; my $td = sub { my $i = shift; return map { td( { color =&gt; $_ % 2 ? 'pink' : 'green' }, $i + $_ ) } 0..4; }; say table( { border =&gt; 0, cellpadding =&gt; 4 }, map { &amp;tr( { align =&gt; 'right' }, $td-&gt;( $_ ) ) } loop( below =&gt; 25, by =&gt; 5 ) )-&gt;as_HTML; </code></pre> <p><br /></p> <h2>HTML::Tiny</h2> <pre><code>use HTML::Tiny; my $h = HTML::Tiny-&gt;new; my $td = sub { my $i = shift; return map { $h-&gt;td( { 'color' =&gt; $_ % 2 ? 'pink' : 'green' }, $i + $_ ) } 0..4; }; say $h-&gt;table( { border =&gt; 0, cellpadding =&gt; 4 }, [ map { $h-&gt;tr( { align =&gt; 'right' }, [ $td-&gt;( $_ ) ] ) } loop( below =&gt; 25, by =&gt; 5 ) ] ); </code></pre> <p><br /></p> <h2>Markapl</h2> <pre><code>use Markapl; template 'MyTable' =&gt; sub { table ( border =&gt; 0, cellpadding =&gt; 4 ) { for ( my $i = 1; $i &lt; 25; $i += 5 ) { row ( align =&gt; 'right' ) { for my $j ( 0.. 4 ) { td ( color =&gt; $j % 2 ? 'pink' : 'green' ) { $i + $j } } } } } }; print main-&gt;render( 'MyTable' ); </code></pre> <p><br /></p> <h2>Template::Declare</h2> <pre><code>package MyTemplates; use Template::Declare::Tags; use base 'Template::Declare'; template 'MyTable' =&gt; sub { table { attr { border =&gt; 0, cellpadding =&gt; 4 }; for ( my $i = 1; $i &lt; 25; $i += 5 ) { row { attr { align =&gt; 'right' }; for my $j ( 0..4 ) { cell { attr { color =&gt; $j % 2 ? 'pink' : 'green' } outs $i + $j; } } } } } }; package main; use Template::Declare; Template::Declare-&gt;init( roots =&gt; ['MyTemplates'] ); print Template::Declare-&gt;show( 'MyTable' ); </code></pre> <p><br /></p> <h2>XML::Generator</h2> <pre><code>use XML::Generator; my $x = XML::Generator-&gt;new( pretty =&gt; 2 ); my $td = sub { my $i = shift; return map { $x-&gt;td( { 'color' =&gt; $_ % 2 ? 'pink' : 'green' }, $i + $_ ) } 0..4; }; say $x-&gt;table( { border =&gt; 0, cellpadding =&gt; 4 }, map { $x-&gt;tr( { align =&gt; 'right' }, $td-&gt;( $_ ) ) } loop( below =&gt; 25, by =&gt; 5 ) ); </code></pre> <p><br /> <em>And the following can be used to produce the "loop" in HTML::AsSubs / HTML::Tiny / XML::Generator examples....</em></p> <pre><code>sub loop { my ( %p ) = @_; my @list; for ( my $i = $p{start} || 1; $i &lt; $p{below}; $i += $p{by} ) { push @list, $i; } return @list; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload