use List::Util ();
use Scalar::Util qw/blessed weaken/;
use Try::Tiny;
+use Storable qw/nfreeze thaw/;
use namespace::clean;
use overload
sub search {
my $self = shift;
my $rs = $self->search_rs( @_ );
- return (wantarray ? $rs->all : $rs);
+
+ my $want = wantarray;
+ if ($want) {
+ return $rs->all;
+ }
+ elsif (defined $want) {
+ return $rs;
+ }
+ else {
+ $self->throw_exception ('->search is *not* a mutator, calling it in void context makes no sense');
+ }
}
=head2 search_rs
}
my $call_attrs = {};
- $call_attrs = pop(@_) if @_ > 1 and ref $_[-1] eq 'HASH';
+ $call_attrs = pop(@_) if (
+ @_ > 1 and ( ! defined $_[-1] or ref $_[-1] eq 'HASH' )
+ );
# see if we can keep the cache (no $rs changes)
my $cache;
} if @_;
+ carp 'search( %condition ) is deprecated, use search( \%condition ) instead'
+ if (@_ > 1 and ! $self->result_source->result_class->isa('DBIx::Class::CDBICompat') );
+
for ($old_where, $call_cond) {
if (defined $_) {
$new_attrs->{where} = $self->_stack_cond (
return $orig;
}
+
sub result_source {
my $self = shift;
}
}
+
+sub STORABLE_freeze {
+ my ($self, $cloning) = @_;
+ my $to_serialize = { %$self };
+
+ # A cursor in progress can't be serialized (and would make little sense anyway)
+ delete $to_serialize->{cursor};
+
+ return nfreeze($to_serialize);
+}
+
+# need this hook for symmetry
+sub STORABLE_thaw {
+ my ($self, $cloning, $serialized) = @_;
+
+ %$self = %{ thaw($serialized) };
+
+ return $self;
+}
+
+
=head2 throw_exception
See L<DBIx::Class::Schema/throw_exception> for details.