Skip Menu |

This queue is for tickets about the Moose CPAN distribution.

Report information
The Basics
Id: 39001
Status: resolved
Priority: 0/
Queue: Moose

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.56
Fixed in: (no value)



Subject: No protection against extending yourself.
I made an innocent mistake: package Bar; use Moose; package Foo; use Moose; extends Bar; This results in: Deep recursion on subroutine "MRO::Compat::__get_linear_isa_dfs" at /usr/local/lib/site_perl/MRO/Compat.pm line 123. The lack of quoting on "extends Bar" means it's "Bar->extends" so Bar is trying to extend itself. The problem can simply be reduced to: package Bar; use Moose; extends Bar; There's no protection against extending yourself. Patch is attached.
Subject: extends.patch
--- Moose-0.57/lib/Moose.pm 2008-09-03 11:39:24.000000000 -0700 +++ Moose-0.57.patched/lib/Moose.pm 2008-09-04 16:56:32.000000000 -0700 @@ -43,6 +43,9 @@ my @supers = @_; foreach my $super (@supers) { + croak "You cannot extend yourself" + if $super eq $class; + Class::MOP::load_class($super); croak "You cannot inherit from a Moose Role ($super)" if $super->can('meta') && --- /dev/null 2008-09-04 17:01:58.000000000 -0700 +++ Moose-0.57.patched/t/extend_yourself.t 2008-09-04 17:01:41.000000000 -0700 @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More 'no_plan'; +use Test::Exception; + +{ + package Foo; + use Moose; + + ::throws_ok { + extends "Foo"; + } qr/^You cannot extend yourself/; +}
Hi Michael, Can you email/msg me or mst htpasswd -n credentials so we can add you to Moose's svn?
Subject: Re: [rt.cpan.org #39001] No protection against extending yourself.
Date: Thu, 4 Sep 2008 20:36:12 -0500 (CDT)
To: יובל קוג'מן via RT <bug-Moose [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Thu, 4 Sep 2008, יובל קוג'מן via RT wrote: Show quoted text
> Can you email/msg me or mst htpasswd -n credentials so we can add you to Moose's svn?
This is the wrong place to check this stuff. I think we should do it when superclasses is set. Also, we might as well check for circular deps at the same time. -dave /*========================== VegGuide.Org Your guide to all that's veg ==========================*/
Subject: Re: [rt.cpan.org #39001] No protection against extending yourself.
Date: Fri, 5 Sep 2008 18:07:45 +0300
To: "autarch [...] urth.org via RT" <bug-Moose [...] rt.cpan.org>
From: Yuval Kogman <nothingmuch [...] woobling.org>
On Thu, Sep 04, 2008 at 21:37:02 -0400, autarch@urth.org via RT wrote: Show quoted text
> Queue: Moose > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=39001 > > > On Thu, 4 Sep 2008, יובל קוג'מן via RT wrote: >
> > Can you email/msg me or mst htpasswd -n credentials so we can add you to Moose's svn?
> > This is the wrong place to check this stuff. I think we should do it when > superclasses is set. Also, we might as well check for circular deps at the > same time.
Circular inheritence is checked for already -- Yuval Kogman <nothingmuch@woobling.org> http://nothingmuch.woobling.org 0xEBD27418
Subject: Re: [rt.cpan.org #39001] No protection against extending yourself.
Date: Fri, 5 Sep 2008 10:10:14 -0500 (CDT)
To: "nothingmuch [...] woobling.org via RT" <bug-Moose [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Fri, 5 Sep 2008, nothingmuch@woobling.org via RT wrote: Show quoted text
> Queue: Moose > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=39001 > > > On Thu, Sep 04, 2008 at 21:37:02 -0400, autarch@urth.org via RT wrote:
>> Queue: Moose >> Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=39001 > >> >> On Thu, 4 Sep 2008, יובל קוג'מן via RT wrote: >>
>>> Can you email/msg me or mst htpasswd -n credentials so we can add you to Moose's svn?
>> >> This is the wrong place to check this stuff. I think we should do it when >> superclasses is set. Also, we might as well check for circular deps at the >> same time.
> > Circular inheritence is checked for already
Shouldn't it catch self-inheritance, then? -dave /*========================== VegGuide.Org Your guide to all that's veg ==========================*/
Subject: Re: [rt.cpan.org #39001] No protection against extending yourself.
Date: Fri, 5 Sep 2008 18:40:36 +0300
To: "autarch [...] urth.org via RT" <bug-Moose [...] rt.cpan.org>
From: Yuval Kogman <nothingmuch [...] woobling.org>
Show quoted text
> Shouldn't it catch self-inheritance, then?
Perl itself does that (5.10 on assignment to @ISA, 5.8 on any method call). Arguably it should. Moose calls ->isa after assigning to @ISA on 5.8 to get the check to happen. -- Yuval Kogman <nothingmuch@woobling.org> http://nothingmuch.woobling.org 0xEBD27418
Hi Schwern, I've added an explicit method call to the superclasses method of Class::MOP::Class. It turns out that the method nothingmuch mentioned isn't called in time. MRO::Compat falls into an infinite loop of superclasses before we call the method. So we now call the method isa (but do nothing with it) immediately after setting @ISA to confirm that there are no cycles in the class hierarchy. Whereas before, on 5.8.8, we got: perl -Moose -e 'extends Class' Deep recursion on subroutine "MRO::Compat::__get_linear_isa_dfs" at / opt/local/lib/perl5/site_perl/5.8.8/MRO/Compat.pm line 123. We now get the less cryptic: Recursive inheritance detected while looking for method 'isa' in package 'Class' at lib//Class/MOP/Class.pm line 509. Thanks for the report! Shawn