Skip to content

Commit

Permalink
Warn on signs of Moose-borkage (in case it gets to be the first new())
Browse files Browse the repository at this point in the history
  • Loading branch information
ribasushi committed Feb 26, 2013
1 parent 482a1cf commit e0de554
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Changes
@@ -1,5 +1,9 @@
Revision history for DBIx::Class

* New Features / Changes
- Debugging aid - warn on invalid result objects created by what
seems like an invalid inheritance hierarchy

* Fixes
- Fix another embarrassing regression preventing correct refining of
the search criteria on a prefetched relation (broken in 0.08205)
Expand Down
26 changes: 20 additions & 6 deletions lib/DBIx/Class/ResultSet.pm
Expand Up @@ -5,7 +5,7 @@ use warnings;
use base qw/DBIx::Class/;
use DBIx::Class::Carp;
use DBIx::Class::ResultSetColumn;
use Scalar::Util qw/blessed weaken/;
use Scalar::Util qw/blessed weaken reftype/;
use Try::Tiny;
use Data::Compare (); # no imports!!! guard against insane architecture

Expand Down Expand Up @@ -2324,15 +2324,29 @@ sub new_result {

my ($merged_cond, $cols_from_relations) = $self->_merge_with_rscond($values);

my %new = (
my $new = $self->result_class->new({
%$merged_cond,
@$cols_from_relations
( @$cols_from_relations
? (-cols_from_relations => $cols_from_relations)
: (),
: ()
),
-result_source => $self->result_source, # DO NOT REMOVE THIS, REQUIRED
);
});

if (
reftype($new) eq 'HASH'
and
! keys %$new
and
blessed($new)
) {
carp_unique (sprintf (
"%s->new returned a blessed empty hashref - a strong indicator something is wrong with its inheritance chain",
$self->result_class,
));
}

return $self->result_class->new(\%new);
$new;
}

# _merge_with_rscond
Expand Down

0 comments on commit e0de554

Please sign in to comment.