Commit | Line | Data |
b8e1e21f |
1 | package DBIx::Class::CDBICompat::HasA; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | sub has_a { |
4a07648a |
7 | my ($self, $col, $f_class, %args) = @_; |
701da8c4 |
8 | $self->throw_exception( "No such column ${col}" ) unless $self->has_column($col); |
b8e1e21f |
9 | eval "require $f_class"; |
22b15c96 |
10 | if ($args{'inflate'} || $args{'deflate'}) { # Non-database has_a |
4a07648a |
11 | if (!ref $args{'inflate'}) { |
12 | my $meth = $args{'inflate'}; |
13 | $args{'inflate'} = sub { $f_class->$meth(shift); }; |
14 | } |
15 | if (!ref $args{'deflate'}) { |
16 | my $meth = $args{'deflate'}; |
17 | $args{'deflate'} = sub { shift->$meth; }; |
18 | } |
19 | $self->inflate_column($col, \%args); |
20 | return 1; |
21 | } |
22b15c96 |
22 | |
07037f89 |
23 | $self->belongs_to($col, $f_class); |
b8e1e21f |
24 | return 1; |
25 | } |
26 | |
b98e75f6 |
27 | sub search { |
28 | my $self = shift; |
29 | my $attrs = {}; |
30 | if (@_ > 1 && ref $_[$#_] eq 'HASH') { |
31 | $attrs = { %{ pop(@_) } }; |
32 | } |
33 | my $where = (@_ ? ((@_ == 1) ? ((ref $_[0] eq "HASH") ? { %{+shift} } : shift) |
34 | : {@_}) |
35 | : undef()); |
36 | if (ref $where eq 'HASH') { |
37 | foreach my $key (keys %$where) { # has_a deflation hack |
38 | $where->{$key} = ''.$where->{$key} |
39 | if eval { $where->{$key}->isa('DBIx::Class') }; |
40 | } |
41 | } |
42 | $self->next::method($where, $attrs); |
43 | } |
44 | |
b8e1e21f |
45 | 1; |