encutened examples
[catagits/CatalystX-Declare.git] / examples / MyApp-Web / lib / MyApp / Web / Controller / Calc.pm
1 use CatalystX::Declare;
2
3 # this "calculator" (mind the quotes) is extendable by the model
4 controller MyApp::Web::Controller::Calc {
5
6     # we base of the common base in the root controller
7     action base as calc under '/base';
8
9     # we fetch our operator from the model in an action attached to the base
10     action operator <- base (Str $op) as '' {
11         $ctx->stash(operator => $ctx->component('Model::Calc')->op($op));
12     }
13
14     # here we know we have an operator and run it against the integers we got
15     final action evaluate <- operator (Int @nums) as '' {
16         $ctx->response->body($ctx->stash->{operator}->(@nums));
17     }
18 }