Pavel Karoukin > Mojolicious-Plugin-Sugar > Mojolicious::Plugin::Sugar

Download:
Mojolicious-Plugin-Sugar-0.002.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.002   Source  

NAME ^

Mojolicious::Plugin::Sugar - Some sweet stuff for Mojolicious

VERSION ^

version 0.002

SYNOPSIS ^

    # Mojolicious
    $self->plugin('Sugar');

    # Mojolicious::Lite
    plugin 'Sugar';

    # To add more than one flash values, for messages, for example.
    $self->flash_add_to( 'messages' => 'message one' );
    $self->flash_add_to( 'messages' => 'message two' );
    $self->flash_add_to( 'messages' => 'message three', 'message four' );
    $self->redirect_to( '/list' );

    @@ list.html.ep
    % foreach my $msg ( @{ flash messages } ) {
    <li><%= $msg %>
    % }

    # Shortcut to process HTML::FormHandler form 
    my $form = MyApp::Form::Add->new;
    $form->process( $self->params->to_hash );

    if ($form->validated) {
      [...]
    }
    else {
      [...]
    }

DESCRIPTION ^

Mojolicious::Plugin::Sugar is a Mojolicious plugin that adds few convenience helpers.

NAME ^

Mojolicious::Plugin::Sugar - sugary helpers for your Mojolicious app

HELPERS ^

flash_add_to

    $self->flash_add_to( 'messages' => 'message one' );
    $self->flash_add_to( 'messages' => 'message two' );

This helper allow you to add multiple values into flash variables. It creates referenced array when first called and all next calls will add additional elements into this array. Later in your template you can do something like this:

    @@ list.html.ep
    % foreach my $msg ( @{ flash messages } ) {
    <li><%= $msg %>
    % }

You can also specify more than one value in one call:

    $self->flash_add_to( 'messages' => 'message three', 'message four' );

To overwrite flash variable simply use standard $self->flash() call.

AUTHOR ^

Pavel A. Karoukin <pavel@karoukin.us>

BUGS ^

Please report any bugs or feature requests to Github https://github.com/hippich/perl-mojolicious-plugin-sugar

SEE ALSO ^

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

AUTHOR ^

Pavel A. Karoukin <pavel@karoukin.us>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2012 by Pavel A. Karoukin <pavel@karoukin.us>.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: