3 use HTTP::Request::Common;
7 package Local::Model::Foo;
10 extends 'Catalyst::Model';
12 has a => (is=>'ro', required=>1);
14 sub foo { shift->a . 'foo' }
16 package Local::Controller::Errors;
19 use MooseX::MethodAttributes;
21 extends 'Catalyst::Controller';
23 has ['a', 'b'] => (is=>'ro', required=>1);
25 sub not_found :Local { pop->res->from_psgi_response([404, [], ['Not Found']]) }
27 package MyApp::Model::User;
28 $INC{'MyApp/Model/User.pm'} = __FILE__;
31 extends 'Catalyst::Model';
33 has 'zoo' => (is=>'ro', required=>1, isa=>'Object');
35 around 'COMPONENT', sub {
36 my ($orig, $class, $app, $config) = @_;
37 $config->{zoo} = $app->model('Zoo');
39 return $class->$orig($app, $config);
43 1 => { name => 'john', age => 46 },
44 2 => { name => 'mary', age => 36 },
45 3 => { name => 'ian', age => 25 },
46 4 => { name => 'visha', age => 18 },
51 my $user = $users{$id} || return;
52 return bless $user, "MyApp::Model::User::user";
55 package MyApp::Controller::Root;
56 $INC{'MyApp/Controller/Root.pm'} = __FILE__;
59 use MooseX::MethodAttributes;
61 extends 'Catalyst::Controller';
63 sub user :Local Args(1) {
64 my ($self, $c, $int) = @_;
66 Test::More::ok(my $user = $c->model("User")->find($int));
67 Test::More::ok($c->model("User")->zoo->a);
69 $c->res->body("name: $user->{name}, age: $user->{age}");
72 sub default :Default {
73 my ($self, $c, $int) = @_;
74 $c->res->body('default');
77 MyApp::Controller::Root->config(namespace=>'');
83 'Controller::Err' => {
84 from_component => 'Local::Controller::Errors',
85 args => { a=> 100, b => 200, namespace =>'error' },
88 from_component => 'Local::Model::Foo',
92 from_component => 'Local::Model::Foo',
100 use Catalyst::Test 'MyApp';
103 my $res = request '/user/1';
104 is $res->content, 'name: john, age: 46';
108 my $res = request '/error/not_found';
109 is $res->content, 'Not Found';