Contentment::Form::Widget::Label - A very simple label widget
This class adds the label() method to Contentment::Form::Widget. This method can automatically generate a label for any widget that returns a proper value for the id() method. It also takes the same arguments as the constructor, which can be used to set additional parameters:
label()
id()
[% form.widgets.username.label( content = "Luser Name" ).render %]
You may choose to use either the render() or begin()/end() methods to render the widget. However, if you use begin()/end() make sure to manually set content to an empty string:
render()
begin()
end()
[% SET label = form.widgets.username.label(content = "") %] [% label.begin %]Luser Name[% label.end %]
This would render the same HTML as the code above, which sets the content option to "Luser Name".
The widget constructor takes the following arguments:
This should be either the ID of the widget this label belongs to or it may be the widget object itself the label should point to.
This label class attempts to be a little smarter with creating the displayed label name. If you pick control names that follow a simple convention, this will convert the control name into a pretty capitalized name.
For example,
my $form = Contentment::Form->define( # ... widgets => { username => { name => 'username', # ID will be "username" class => 'Text', }, full_name => { name => 'full_name', # ID will be "full_name" class => 'Text', }, }, # ... ); # ...
renders:
<label for="username">Username</label> <label for="full_name">Full Name</label>
All underscores in the ID are replaced with spaces and the string is converted to title-case.
Andrew Sterling Hanenkamp, <hanenkamp@cpan.org>
Copyright 2005 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>. All Rights Reserved.
This module 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 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To install Contentment, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Contentment
CPAN shell
perl -MCPAN -e shell install Contentment
For more information on module installation, please visit the detailed CPAN module installation guide.