The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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.