Subject: | Extending a non-Moo class has unexpected behavior on blessed new |
Date: | Wed, 15 Feb 2017 19:30:54 +0000 |
To: | "bug-Moo [...] rt.cpan.org" <bug-Moo [...] rt.cpan.org> |
From: | Aran Deltac <bluefeet [...] gmail.com> |
TEST:
package VanillaRS;
use base 'DBIx::Class::ResultSet';
package MooRS;
use Moo;
extends 'DBIx::Class::ResultSet';
package main;
use Test2::Bundle::Extended ':v1';
my $vanilla_rs = bless {}, 'VanillaRS';
my $moo_rs = bless {}, 'MooRS';
my $expected_exception = dies { $vanilla_rs->new() };
is(
dies { $moo_rs->new() },
"$expected_exception",
);
done_testing;
OUTPUT:
not ok 1
# Failed test at test-rs.pl line 18.
#
+-------------------------------------------+----+-------------------------------------------+
# | GOT | OP | CHECK
|
#
+-------------------------------------------+----+-------------------------------------------+
# | Can't call method "isa" on an undefined v | eq |
DBIx::Class::ResultSet::new_result(): Res |
# | alue at /home/aran/local-lib/lib/perl5/DB | | ult object
instantiation requires a hashr |
# | Ix/Class/ResultSet.pm line 310.\n | | ef as argument at
test-rs.pl line 14\n |
#
+-------------------------------------------+----+-------------------------------------------+
CONCLUSION:
Under Moo it seems that the parent classes' new is called with a package
name no matter what, even if the child class's new was called on a blessed
object. This is unexpected and weird behavior to me, and makes it so that,
in my case, DBIx::Class::ResultSet's weird behavior of acting differently
if new is called on a package instead of an object be disabled. While I
like the removal of weird behavior, my many tens/hundreds of thousands of
lines of existing code does not and prevents me from using Moo everywhere I
would like. :)