|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Multiple inheritance of controllersI'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/ [subclassed_chained.diff] 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: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
RE: Multiple inheritance of controllersI ran into the same problem. But I found that adding this to my controllers that inherit from multiple controller base classes works as a work around:
use Class::C3; sub create_action { my $self = shift; return $self->maybe::next::method(@_); } It's an annoying workaround, but I didn't have time to pursue the issue any further :P Does anybody know why this might be happening? Anyway, I hope that helps somewhat.. Byron Zbigniew Lukasiak wrote on 2008-06-13: > 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/ _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
|
|
Re: Multiple inheritance of controllersOn Sat, Jun 14, 2008 at 12:24 AM, Byron Young <Byron.Young@...> wrote:
> I ran into the same problem. But I found that adding this to my controllers that inherit from multiple controller base classes works as a work around: > > use Class::C3; > > sub create_action { > my $self = shift; > > return $self->maybe::next::method(@_); > } > > It's an annoying workaround, but I didn't have time to pursue the issue any further :P Does anybody know why this might be happening? > > Anyway, I hope that helps somewhat.. Unfortunately it did not help - and I encountered one more strange behaviour. So basically I changed the test controller to: ======================= package Base; use strict; use warnings; use base qw/Catalyst::Controller/; sub basefoo :Local { } package Intermediate; use strict; use warnings; use base qw/Catalyst::Controller Base/; # this one does not inherit actions from Base package TestApp::Controller::Action::Subclassed; use strict; use warnings; use Class::C3; sub create_action { my $self = shift; return $self->maybe::next::method(@_); } use base qw/Intermediate/; 1; ======================= But I got following error: t/subclassed......Inconsistent hierarchy during C3 merge of class 'Intermediate': merging failed on parent 'Catalyst::Controller' at /usr/local/lib/perl/5.8.8/Class/C3/XS.pm line 64. So I changed that to: ======================= package Base2; use strict; use warnings; use base qw/Catalyst::Controller/; package Base; use strict; use warnings; use base qw/Catalyst::Controller/; sub basefoo :Local { } package Intermediate; use strict; use warnings; use base qw/Base2 Base/; # this one does not inherit actions from Base package TestApp::Controller::Action::Subclassed; use strict; use warnings; use Class::C3; sub create_action { my $self = shift; return $self->maybe::next::method(@_); } use base qw/Intermediate/; 1; ======================== Mysteriously this one compiles OK - but basefoo still is not inherited. -- Zbigniew > > Zbigniew Lukasiak wrote on 2008-06-13: >> 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/ > > > > _______________________________________________ > List: Catalyst@... > Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst > Searchable archive: http://www.mail-archive.com/catalyst@.../ > Dev site: http://dev.catalyst.perl.org/ > > -- Zbigniew Lukasiak http://brudnopis.blogspot.com/ http://perlalchemy.blogspot.com/ _______________________________________________ List: Catalyst@... Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@.../ Dev site: http://dev.catalyst.perl.org/ |
| Free Forum Powered by Nabble | Forum Help |