Alister West

home is where your code is ...

Perl Mojolicious CheatSheet

A bunch of stuff I always forget.

TagHelpers

%= label_for 'name' => 'value', @attribs;
or
%= label_for 'name', @attribs, begin
    name as a code block
% end

# Hidden fields
%= hidden_field id => '';                   # NO auto-populate from params
%= input_tag id => '', type => 'hidden';    # WILL auto-populate FTW!

Validation

use Regexp::Common qw/Email::Address/;

get '/foo' => sub {
    my $self = shift;
    return $self->render unless $self->validation->has_data;
    $self->validation->required('foo');
    $self->validation->required('email')->like( qr/^$RE{Email}{Address}$/ );
    $self->render('index');
};
...
@@ index.html.ep
%# == dumper validation;
Errors: <%= validation->has_error("foo") ? validation->errors("foo")->[0] : "" %>
%= label_for "foo", "my label", class => "red", required => "required";
%= text_field "foo", class => "custom";
By Alister West