choroba, I added get_attributes (formerly build_attributes) to the module, and it is much better now. I hope you do not mind I made a few changes to suit my finickiness. I have not made any other changes yet, still figuring it out. Thank you very much for the nudge regarding the attributes!

package Base::HTML::Elements; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK = qw(table cols col row cell list); use Base::Nifty qw(line); sub get_attributes { my ($options, $valid) = @_; my @attributes; for (@{$valid}) { my $value = $options->{$_}; push @attributes, qq($_="$value") if $options->{$_}; } return join(' ',('',@attributes)); } sub list { my ($tab,$type,$list,$opt) = @_; my $attributes = get_attributes($opt,['id','class','style']); my $tag = $type.'l'; my $open = $tag.$attributes; line($tab,qq(<$open>)); line($tab + 1,qq(<li>$_</li>)) for @$list; line($tab,qq(</$tag>)); } sub cell { my ($tab,$type,$contents,$opt) = @_; my $attributes = get_attributes($opt,['id','class','style','colspan' +,'rowspan']); my $tag = 't'.$type; my $open = $tag.$attributes; line($tab,qq(<$open>)); if ($contents =~ /list/i) { list($tab + 1,@{$opt->{list}}); } else { line($tab + 1,$contents); } line($tab,qq(</$tag>)); } sub row { my ($tab,$type,$cells,$opt) = @_; my %types = ( header => 'h', data => 'd', whead => 'd' ); my $attributes = get_attributes($opt,['id','class','style']); my $open = 'tr'.$attributes; line($tab,qq(<$open>)); if ($type eq 'whead') { my $cell = shift @{$cells}; cell($tab + 1,'h',ucfirst $cell, { class => 'row_header' }); } my $cell_type = $types{$type}; for my $cell (@{$cells}) { if (ref($cell) eq 'ARRAY') { cell($tab + 1,$cell_type,$cell->[0],$cell->[1]); } else { cell($tab + 1,$cell_type,$cell); } } line($tab,q(</tr>)); } sub col { my ($tab,$opt) = @_; my $attributes = get_attributes($opt,['id','class','span']); my $open = 'col'.$attributes; line($tab,qq(<$open>)); } sub cols { my ($tab,$cols) = @_; col($tab,$_) for @{$cols}; } sub table { my ($tab,$opt) = @_; my $attributes = get_attributes($opt,['id','class','style']); my $open = 'table'.$attributes; line($tab,qq(<$open>)); line($tab + 1,qq(<caption>$opt->{caption}</caption>)) if $opt->{capt +ion}; row($tab + 1,'header',$opt->{headings}) if $opt->{headings}; if ($opt->{data}) { row($tab + 1,'data',$_) for @{$opt->{data}}; } if ($opt->{whead}) { row($tab + 1,'whead',$_) for @{$opt->{whead}}; } line($tab,q(</table>)); } 1;

Update: The above code was altered to include the new get_attributes two posts (as of this writing) down. The original code was...

sub get_attributes { my ($options, $valid) = @_; my @attributes; for (@{$valid}) { my $value = $options->{$_}; push @attributes, qq($_="$value") if $options->{$_}; } return [@attributes]; }
Have a cookie and a very nice day!
Lady Aleena

In reply to Re^2: I'm stuck adding more named parameters to a subroutine since the new named parameters might have the same name as the current ones. by Lady_Aleena
in thread I'm stuck adding more named parameters to a subroutine since the new named parameters might have the same name as the current ones. by Lady_Aleena

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.