Name
HTML::Accessors - Generate HTML elements
Version
0.1.$Rev: 10 $
Synopsis
use HTML::Accessors;
my $htag = HTML::Accessors->new();
# Create an anchor element
$anchor = $htag->a( { href => 'http://...' }, 'This is a link' );
Description
Uses HTML::GenerateUtil to create an autoload method for each of the elements defined by HTML::Tagset. The API was loosely taken from CGI. Using the CGI module is undesirable in a Catalyst application (run from the development server) due go greediness issues over STDIN.
The returned tags are XHTML 1.1 compliant.
Subroutines/Methods
new
The constructor is inherited from Class::Accessor::Fast and takes no options
escape_html
Expose HTML::GenerateUtil::escape_html
popup_menu
Returns the <select>
element. The first option passed to popup_menu
is either a hash ref or a list of key/value pairs. The keys are:
- default Determines which of the values will be selected by default
- labels Display these labels in place of the values (but return the value of the selected label). This is a hash ref with a key for each element in the
values
array - values The key references an array ref whose values are used as the list of options returned in the body of the
<select>
element.
The rest of the keys and values are passed as attributes to the <select>
element. For example:
$ref = { default => 1, name => q(my_field), values => [ 1, 2 ] };
$htag->popup_menu( $ref );
would return:
E<lt>select name="my_field"E<gt>
E<lt>option selected="selected"E<gt>1E<lt>/optionE<gt>
E<lt>optionE<gt>2E<lt>/optionE<gt>
E<lt>/selectE<gt>
radio_group
Generates a list of radio input buttons with labels. Break elements can be inserted to create rows of a given number of columns when displayed. The first option passed to radio_group
is either a hash ref or a list of key/value pairs. The keys are:
For example:
$ref = { columns => 2,
default => 1,
labels => { 1 => q(Button One),
2 => q(Button Two),
3 => q(Button Three),
4 => q(Button Four), },
name => q(my_field),
values => [ 1, 2, 3, 4 ] };
$htag->radio_group( $ref );
would return:
E<lt>label>
E<lt>input checked="checked" tabindex="1" value="1" name="my_field" type="radio" />Button One
E<lt>/label>
E<lt>label>
E<lt>input tabindex="2" value="2" name="my_field" type="radio" />Button Two
E<lt>/label>
E<lt>br />
E<lt>label>
E<lt>input tabindex="3" value="3" name="my_field" type="radio" />Button Three
E<lt>/label>
E<lt>label>
E<lt>input tabindex="4" value="4" name="my_field" type="radio" />Button Four
E<lt>/label>
E<lt>br />
scrolling_list
Calls popup_menu
with the multiple
argument set to multiple
. This has the effect of allowing multiple selections to be returned from the popup menu
AUTOLOAD
Uses HTML::Tagset to check if the requested method is a known HTML element. If it is AUTOLOAD
uses HTML::GenerateUtil to create the tag.
If the first option is a hash ref then the keys and values are copied and passed to HTML::GenerateUtil::generate_tag
which uses them to set the attributes on the created element. The next option is treated as the element's body text and overrides the default
attribute which is passed and deleted from the options hash.
If the requested element exists in the hard coded list of input elements, then the element is set to input
and the mapped value used as the type attribute in the call to generate_tag
. For example;
$htag->textfield( { default => q(default value), name => q(my_field) } );
would return
E<lt>input value="default value" name="my_field" type="text" />
The list of input elements contains; button, checkbox, hidden, image_button, password_field, radio_button, submit, and textfield
DESTROY
Implement the DESTROY
method so that the AUTOLOAD
method doesn't get called instead. Re-dispatches the call upstream.
_carp
Call Carp::carp
. Don't load Carp if we don't have to
_croak
Call Carp::croak
. Don't load Carp if we don't have to
Configuration and Environment
None
Diagnostics
Carp::carp
is called to issue a warning about undefined elements
Dependencies
Incompatibilities
There are no known incompatibilities in this module.
Bugs and Limitations
There are no known bugs in this module. Please report problems to the address below. Patches are welcome.
Author
Peter Flanigan, <Support at RoxSoft.co.uk>
License and Copyright
Copyright (c) 2008 Peter Flanigan. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
This program is distributed in the hope that it will be useful, but WITHOUT WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.