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/;
+}