package HTML::LadyAleenaStyle; use strict; use warnings; use Exporter qw(import); our @EXPORT_OK = qw(title script heading anchor paragraph sparagraph list definition_list table form fieldset legend label selection input textarea div pre); use HTML::Entities qw(encode_entities); use Base::Data qw(data_file get_hash); use Base::Nifty qw(sline line); =head1 NAME B generates HTML tags for most of the HTML elements. =head1 SYNOPSIS To use B to print HTML tags, use the following. use Base::HTML::Element qw( title heading script anchor paragraph sparagraph list definition_list table form fieldset selection input textarea div pre ); ## Module Vars =head3 C To print readable html, set the indentation to the level. Can be 0 - 9. Each level constitutes a tab space multiplier applied to child elements (according to dominterpretation?). Default is no indentation in output or 0 level. $HTML::LadyAleenaStyle::inlvl = 7; Each child element will be indented seven tab stops from the relevant parent element =cut $HTML::LadyAleenaStyle::inlvl = 0 unless $HTML::LadyAleenaStyle::inlvl; # default indentation none; ### set module variables if required in calling script. sub in_depth { state $level = 0; # requires Perl version 5.10 return ( sub { $level += $HTML::LadyAleenaStyle::inlvl }, sub { $level -= $HTML::LadyAleenaStyle::inlvl }, ); } my ($ina,$ind) = in_depth; # now replace the $tab variables throughought the element subs with calls to # &$ina for ascending tab depth, # &$ind for descending tab depth, # and remove $tab assignement from secial array. # for example in sub div: # # sub div{ # # my ($code,$opt) = @_; # no $tab # my $tag = 'div'; # my $open = open_tag($tag,$opt,[@ics,@java]); # # line(&$ina,qq(<$open>)); # indent depth increase # &$code; # line(&$ind,qq()); # indent depth decrease # } # ## Module Subs } sub get_attributes { my ($options, $valid) = @_; my @attributes; for (@{$valid}) { my $value = $options->{$_}; push @attributes, qq($_="$value") if defined($options->{$_}); } return join(' ',('',@attributes)); } sub open_tag { my ($tag,$opt,$attributes) = @_; my $tag_attributes = get_attributes($opt,$attributes); return $tag.$tag_attributes; } sub plain_element { my ($tag,$attributes,$tab,$value,$opt) = @_; my $open = open_tag($tag,$opt,$attributes); return sline($tab,"<$open>$value"); } ## lexical vars #? maybe should be package variables? unless restricting access, then should be constants? my @ics = ('id','class','style'); my @java = qw(onclick ondblclick onkeypress onkeydown onkeyup onmouseover onmousedown onmouseup onmousemove onmouseout); =head1 FUNCTIONS All of the functions C the elements with the exception of C which returns the anchor and C which returns a paragraph for use in other functions. As with the Perl community, the HTML community expects some indentation so tabs, the first parameter of every function, are included with each element except where noted. The last parameter of every element is a hash with named options except where noted. Most elements have the C, C, C