I've tried to build a module that would merge two base controllers and
then use it as another base controller. Unfortunately it looks like
only actions from the first base class in the 'use base ...' phrase
are being inherited:
I've created a test case for that - it is attached and I paste it
below for your convenience.
If someone sent me some instructions how to modify it to fit into the
Moose model I'll test it on the Moose branch as well (I am not sure if
they would be base controllers there at all - perhaps Roles instead?).
Cheers,
Zbigniew
package TestApp::Controller::Action::SubclassedChained;
use strict;
use warnings;
use base qw/Intermediate/;
1;
==================================================================
package Intermediate;
use strict;
use warnings;
use base qw/Catalyst::Controller::REST Base/; # this one does not
inherit actions from Base
#use base qw/Base Catalyst::Controller::REST/; # this one does
1;
==================================================================
package Base;
use strict;
use warnings;
use base qw/Catalyst::Controller/;
sub basefoo :CaptureArgs(1) :Chained('/') { }
sub baseendpoint :Args(1) :Chained('basefoo') { }
1;
--
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
http://perlalchemy.blogspot.com/
Index: t/sublcassed_chained.t
===================================================================
--- t/sublcassed_chained.t (revision 0)
+++ t/sublcassed_chained.t (revision 0)
@@ -0,0 +1,34 @@
+#!perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+our $iters;
+
+BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
+
+use Test::More tests => 2;
+use Catalyst::Test 'TestApp';
+
+ #
+ # This is a simple test where the parent and child actions are
+ # within the same controller.
+ #
+ {
+ my @expected = qw[
+ TestApp::Controller::Action->begin
+ TestApp::Controller::Action::SubclassedChained->basefoo
+ TestApp::Controller::Action::SubclassedChained->baseendpoint
+ TestApp->end
+ ];
+
+ my $expected = join( ", ", @expected );
+
+ ok( my $response = request('http://localhost//basefoo/1/baseendpoint/2'), 'subclassed chained + local endpoint' );
+ is( $response->header('X-Catalyst-Executed'),
+ $expected, 'Executed actions' );
+ }
+
Index: t/lib/TestApp/Controller/Action/SubclassedChained.pm
===================================================================
--- t/lib/TestApp/Controller/Action/SubclassedChained.pm (revision 0)
+++ t/lib/TestApp/Controller/Action/SubclassedChained.pm (revision 0)
@@ -0,0 +1,9 @@
+package TestApp::Controller::Action::SubclassedChained;
+
+use strict;
+use warnings;
+
+use base qw/Intermediate/;
+
+1;
+
Index: t/lib/Intermediate.pm
===================================================================
--- t/lib/Intermediate.pm (revision 0)
+++ t/lib/Intermediate.pm (revision 0)
@@ -0,0 +1,10 @@
+package Intermediate;
+
+use strict;
+use warnings;
+
+use base qw/Catalyst::Controller Base/; # this one does not inherit actions from Base
+#use base qw/Base Catalyst::Controller/; # this one works
+
+1;
+
Index: t/lib/Base.pm
===================================================================
--- t/lib/Base.pm (revision 0)
+++ t/lib/Base.pm (revision 0)
@@ -0,0 +1,11 @@
+package Base;
+
+use warnings;
+
+use base qw/Catalyst::Controller/;
+
+sub basefoo :CaptureArgs(1) :Chained('/') { }
+sub baseendpoint :Args(1) :Chained('basefoo') { }
+
+1;
+
_______________________________________________
List: [email protected]
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/