NAME
Mojolicious::Plugin::CountryDropDown - Provide a dropdown where users can select a country
VERSION
version 0.0501
SYNOPSIS
use Mojolicious::Plugin::CountryDropDown;
sub startup {
my $self = shift;
$self->plugin('CountryDropDown');
# or $self->plugin( 'CountryDropDown', { lang => 'de' } );
# to specify the default language for the country names
}
In your controller:
get '/' => sub {
my $self = shift;
$self->show_country_list(); # this sets "country_drop_down" in the stash
};
In your template (this time with TemplateToolkit syntax):
[% country_drop_down %]
Alternatively - using 0.05_01 and up - you can omit the show_country_list() method call inside the controller and use a helper method directly in the template, e.g.:
[% h.country_drop_down({ lang => 'de' }) %]
NAME
Mojolicious::Plugin::CountryDrowDown - use a dropdown to select countries in your form
WARNINGS
Version 0.04 was the first public release and considered a beta release! Version 0.05_01 includes some API changes and there may be some more coming before version 0.06 is released - so please watch out when updating!
CONFIGURATION
You may pass a hash ref on plugin registration. The only key currently processed is "lang" which can be used to set the default language for the country names. Please refer to the Locale::Country::Multilingual docs for a list of available languages. If you specify an unsupported language, or no "lang" at all, "en" will be used as fallback.
METHODS/HELPERS
code2country
Returns the name for the given country code (ISO 3166 Alpha 2).
my $code = 'DE';
my $name = $self->code2country( $code ); # returns "Germany" unless
# a different default language was
# set when registering the plugin
my $lang = 'fr';
my $name = $self->code2country( $code, $lang ); # returns "Allemange"
country2code
Returns the Alpha 2 code for the given country name:
my $name = 'Allemange';
my $code = $self->country2code( $name ); # returns "DE"
show_country_list
Sets the stash variable with the dropdown ("select" element). The default value used for the "id" and "name" attributes is "country".
The method optionally takes a hash ref as param which may contain one or more of the following keys:
- selected
-
A ISO 3166 Alpha 2 country code denoting a preselected country.
- lang
-
Determines the language of the country names. The default is the value specified when registering the plugin (see above).
- attr
-
The value is another hash ref whose keys are used as HTML attributes of the "select" element. No validity checking is performed regarding attribute names and values.
Unless you specify any values for the attributes "id" and "name" they are both set to "country".
my $selected = 'DE'; # select Germany
my $language = 'fr';
$self->show_country_list( { select => $selected, lang => $language } );
$self->show_country_list( {
select => $selected,
lang => $language,
attr => { id => "cid", name => "cname" }
});
get_country_list
Returns a hash indexed by the Alpha 2 country codes with the country names as values.
You may pass a hash ref as param; the only key in there currently recognized is "lang" which may be used to override the default language for the country names.
AUTHORS
Renee Baecker <module@renee-baecker.de>
Heiko Jansen <jansen@hbz-nrw.de>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2012 by Hochschulbibliothekszentrum NRW (hbz).
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007