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