Skip to content

Instantly share code, notes, and snippets.

@minty
minty / gist:4051592
Created November 10, 2012 16:29
Mojolicious helpers and Mojo::IOLoop
#!/usr/bin/env perl
use Mojolicious::Lite;
use Mojo::IOLoop;
use JSON::XS;
my $json = JSON::XS->new->utf8->pretty;
app->secret('as time goes by');
use strict;
use warnings;
use Test::More;
use lib 't/lib';
# Simulate submitting a form when creating/inserting a new row
# Where the form has a (optional) Select field without a default.
# <select name=format>
# <option></option>
# <option value=1>Paperback</option>
sub edit :Local :MyAction('Admin') {
my ($self, $c, $action_id) = @_;
return $c->response->redirect('/admin/action/list')
if $c->req->param('list');
my $db = $c->model('Item::Action');
if ($action_id) {
my $action = $db->find($action_id)
or return $self->respond_404($c);
use Data::Dumper;
warn Dumper $c->request->parameters;
return if !$form->process(
item_id => $action_id,
schema => $c->model('Item')->schema,
params => $c->request->parameters,
);
warn Dumper $form->values;
gets me
re: App that worked fine under Catalyst 5.7 after upgrading to 5.8
M:C:Product.pm
use strict; use warnings;
package My::Controller::Product;
use parent 'My::Controller::_Base';
With M:C:_Base.pm as:
package My::Types;
use strict;
use warnings;
use MooseX::Types -declare => [qw<MyPosNum>];
use HTML::FormHandler::Types;
subtype MyPosNum,
as 'PositiveNum',
# in HTML::FormHandler::Types
subtype PositiveNum,
as Num,
where { $_ >= 0 },
message { "Must be a positive number" };
# I would like to change the 'message'.
# Is there a way I can sub-class a Moose class,
# and change the 'message' bit of the PositiveNum subtype?
HTML::FormHandler::Types;
subtype PositiveNum,
as Num,
where { $_ >= 0 },
message { "Must be a positive number" };
type { 'not_positive_num' }
subtype PositiveInt,
as Int,
################################################################################
### THIS WORKS
package MyApp::Controller::Redux;
use strict;
use warnings;
use parent 'Catalyst::Controller';
use HTML::FormHandler::Model::DBIC;