name 'MyApp-Web';
all_from 'lib/MyApp/Web.pm';
-requires 'CatalystX::Declare' => '0.001';
+requires 'CatalystX::Declare' => '0.004';
requires 'Catalyst::Runtime' => '5.80007';
requires 'Catalyst::Plugin::ConfigLoader';
requires 'Catalyst::Plugin::Static::Simple';
--- /dev/null
+use CatalystX::Declare;
+
+# this "calculator" (mind the quotes) is extendable by the model
+controller MyApp::Web::Controller::Calc {
+
+ # we base of the common base in the root controller
+ action base as calc under '/base';
+
+ # we fetch our operator from the model in an action attached to the base
+ action operator <- base (Str $op) as '' {
+ $ctx->stash(operator => $ctx->component('Model::Calc')->op($op));
+ }
+
+ # here we know we have an operator and run it against the integers we got
+ final action evaluate <- operator (Int @nums) as '' {
+ $ctx->response->body($ctx->stash->{operator}->(@nums));
+ }
+}
--- /dev/null
+use CatalystX::Declare;
+
+model MyApp::Web::Model::Calc {
+
+ method op (Str $op) {
+
+ if ($op eq 'add') {
+ return sub {
+ my $num = shift;
+ $num += $_
+ for @_;
+ return $num;
+ };
+ }
+ elsif ($op eq 'multiply') {
+ return sub {
+ my $num = shift;
+ $num *= $_
+ for @_;
+ return $num;
+ };
+ }
+ else {
+ return sub { 'unknown operator' };
+ }
+ }
+}
-use MooseX::Declare;
+use CatalystX::Declare;
# nothing special here, so it's just normal MooseX::Declare syntax
-class MyApp::Web::View::Hello extends Catalyst::View {
+view MyApp::Web::View::Hello {
# the process method is the standard method that is forwarded to
method process (Object $ctx) {
--- /dev/null
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+
+use Test::More;
+use Catalyst::Test 'MyApp::Web';
+
+like get('/'), qr/welcome/i, 'root page displays welcome';
+is get('/ifthisisfoundsomeonehasserioustestnamingissues'), 'Page Not Found', 'default captures 404';
+
+is get('/calc/add/3/4/5'), 12, 'addition';
+is get('/calc/multiply/2/3/4'), 24, 'multiplication';
+
+is get('/calc/unknownthingy/3/4/5'), 'unknown operator', 'unknown operator';
+is get('/calc/add/3/f/5'), 'Bad Request', 'bad request';
+
+like get('/foo/hello'), qr/root controller role/, 'root controller role';
+
+is get('/foo/2/3/add'), 5, 'add two';
+is get('/foo/2/3/multiply'), 6, 'multiply two';
+
+is get('/foo/2/f/add'), 'Bad Request', 'bad request capture args';
+
+done_testing;