Mojolicious::Plugin::ParamCondition - Request parameter condition plugin
# Mojolicious::Lite plugin 'ParamCondition'; # Does a paramter "productIdx" exist (i.e. ?productIdx=)? get '/' => (params => [qw(productIdx)]) => sub {...}; # Does a paramter "productIdx" match a word? get '/' => (params => {productIdx => "oranges"}) => sub {...}; # Does a paramter "productIdx" match a regular expression? get '/' => (params => {productIdx => qr/\w/}) => sub { # Does a paramter username exist and does paramter fruit match a word? get '/' => (params => ["username"]) => (params => {fruit => "oranges"}) => sub {
Mojolicious::Plugin::ParamCondition is a routes condition based on the presence and value of request parameters.
Given the following code:
get '/' => (params => ["username"]) => (params => {mode => "bread"}) => sub { my $self = shift; $self->render_text("Buy some bread!."); }; get '/' => (params => ["username"]) => (params => {mode => "login"}) => sub { my $self = shift; $self->render_text("Thank you: logging in."); }; get '/' => (params => ["username"]) => sub { my $self = shift; $self->render_text("Please enter a password"); }; get '/' => sub { my $self = shift; $self->render_text("Good morning."); };
The following GET request will match:
/ -> $self->render(text => "Good morning"); /?username= -> $self->render(text => "Please enter a password"); /?username=Baerbel -> $self->render(text => "Please enter a password"); /?username=Baerbel&mode=login -> $self->render(text => "Thank you: logging in."); /?username=Baerbel&mode=bread -> $self->render(text => "Buy some bread!.");
Mojolicious::Plugin::ParamCondition inherits all methods from Mojolicious::Plugin.
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
To install Mojolicious::Plugin::ParamCondition, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Mojolicious::Plugin::ParamCondition
CPAN shell
perl -MCPAN -e shell install Mojolicious::Plugin::ParamCondition
For more information on module installation, please visit the detailed CPAN module installation guide.