NAME

Mojolicious::Plugin::CountryDropDown - Provide a dropdown where users can select a country

VERSION

version 0.04

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 template (this time with TemplateToolkit syntax):

[% country_drop_down %]

In your controller:

get '/' => sub {
    my $self = shift;
    $self->show_country_list(); # this sets "country_drop_down" in the stash
};

NAME

Mojolicious::Plugin::CountryDrowDown - use a dropdown to select countries in your form

WARNINGS

Version 0.04 is the first public release and for now considered a beta release!

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).

id

The value for the "id" attribute of the "select" element. Defaults to "country".

name

The value for the "name" attribute of the "select" element. Defaults to "country".

my $selected = 'DE'; # select Germany
my $language = 'fr';
$self->show_country_list( { select => $selected, lang => $language } );

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