3 use HTTP::Request::Common;
7 package Local::Controller::Errors;
10 use MooseX::MethodAttributes;
12 extends 'Catalyst::Controller';
14 has ['a', 'b'] => (is=>'ro', required=>1);
16 sub not_found :Local { pop->res->from_psgi_response(404, [], ['Not Found']) }
18 package MyApp::Model::User;
19 $INC{'MyApp/Model/User.pm'} = __FILE__;
21 use base 'Catalyst::Model';
24 1 => { name => 'john', age => 46 },
25 2 => { name => 'mary', age => 36 },
26 3 => { name => 'ian', age => 25 },
27 4 => { name => 'visha', age => 18 },
32 my $user = $users{$id} || return;
33 return bless $user, "MyApp::Model::User::user";
36 package MyApp::Controller::Root;
37 $INC{'MyApp/Controller/Root.pm'} = __FILE__;
40 use MooseX::MethodAttributes;
42 extends 'Catalyst::Controller';
44 sub user :Local Args(1) {
45 my ($self, $c, $int) = @_;
46 my $user = $c->model("User")->find($int);
47 $c->res->body("name: $user->{name}, age: $user->{age}");
50 sub default :Default {
51 my ($self, $c, $int) = @_;
52 $c->res->body('default');
55 MyApp::Controller::Root->config(namespace=>'');
61 'Controller::Err' => {
62 component => 'Local::Controller::Errors'
69 use Catalyst::Test 'MyApp';
72 my $res = request '/user/1';
73 is $res->content, 'name: john, age: 46';