Brian Medley > Mojolicious-Plugin-ParamCondition > Mojolicious::Plugin::ParamCondition

Download:
Mojolicious-Plugin-ParamCondition-0.003.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  2
Open  0
View/Report Bugs
Source  

NAME ^

Mojolicious::Plugin::ParamCondition - Request parameter condition plugin

SYNOPSIS ^

  # 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 {

DESCRIPTION ^

Mojolicious::Plugin::ParamCondition is a routes condition based on the presence and value of request parameters.

Dispatching

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!.");

METHODS ^

Mojolicious::Plugin::ParamCondition inherits all methods from Mojolicious::Plugin.

SEE ALSO ^

Mojolicious, Mojolicious::Guides, http://mojolicio.us.

syntax highlighting: