[Catalyst] Multiple inheritance of controllers
Zbigniew Lukasiak
zzbbyy at gmail.com
Tue Jun 17 17:38:28 BST 2008
On Sat, Jun 14, 2008 at 12:24 AM, Byron Young <Byron.Young at riverbed.com> 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 at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
>
>
--
Zbigniew Lukasiak
http://brudnopis.blogspot.com/
http://perlalchemy.blogspot.com/
More information about the Catalyst
mailing list