1 package # hide from PAUSE
2 DBIx::Class::CDBICompat::ImaDBI;
6 use DBIx::ContextualFetch;
8 use base qw/DBIx::Class/;
10 __PACKAGE__->mk_classdata('_transform_sql_handler_order'
11 => [ qw/TABLE ESSENTIAL JOIN/ ] );
13 __PACKAGE__->mk_classdata('_transform_sql_handlers' =>
17 my ($self, $class, $data) = @_;
18 return $class->result_source_instance->name unless $data;
19 my ($f_class, $alias) = split(/=/, $data);
21 $self->{_classes}{$alias} = $f_class;
22 return $f_class->result_source_instance->name." ${alias}";
26 my ($self, $class, $data) = @_;
27 return join(' ', $class->columns('Essential')) unless $data;
28 return join(' ', $self->{_classes}{$data}->columns('Essential'));
32 my ($self, $class, $data) = @_;
33 my ($from, $to) = split(/ /, $data);
34 my ($from_class, $to_class) = @{$self->{_classes}}{$from, $to};
35 my ($rel_obj) = grep { $_->{class} && $_->{class} eq $to_class }
36 map { $from_class->relationship_info($_) }
37 $from_class->relationships;
39 ($from, $to) = ($to, $from);
40 ($from_class, $to_class) = ($to_class, $from_class);
41 ($rel_obj) = grep { $_->{class} && $_->{class} eq $to_class }
42 map { $from_class->relationship_info($_) }
43 $from_class->relationships;
45 $self->throw_exception( "No relationship to JOIN from ${from_class} to ${to_class}" )
47 my $join = $from_class->storage->sql_maker->_join_condition(
48 $from_class->result_source_instance->resolve_condition(
49 $rel_obj->{cond}, $to, $from) );
56 return $_[0]->storage->dbh;
60 my ($class, @info) = @_;
61 $info[3] = { %{ $info[3] || {}} };
62 $info[3]->{RootClass} = 'DBIx::ContextualFetch';
63 return $class->next::method(@info);
67 return $_[0]->storage->dbh->{Driver}->{Name};
71 my ($class, $name, $sql) = @_;
73 *{"${class}::sql_${name}"} =
77 return $class->storage->sth($class->transform_sql($sql, @_));
79 if ($sql =~ /select/i) {
80 my $meth = "sql_${name}";
81 *{"${class}::search_${name}"} =
83 my ($class, @args) = @_;
84 my $sth = $class->$meth;
86 return $class->sth_to_objects($sth);
92 my ($class, $sth) = @_;
94 while (my $row = $sth->fetchrow_hashref) {
95 push(@ret, $class->inflate_result($class->result_source_instance, $row));
101 my ($class, $sql, @args) = @_;
103 foreach my $key (@{$class->_transform_sql_handler_order}) {
104 my $h = $class->_transform_sql_handlers->{$key};
105 $sql =~ s/__$key(?:\(([^\)]+)\))?__/$h->($attrs, $class, $1)/eg;
108 return sprintf($sql, @args);
112 DBIx::ContextualFetch::st; # HIDE FROM PAUSE THIS IS NOT OUR CLASS
114 no warnings 'redefine';
116 sub _untaint_execute {
118 my $old_value = $sth->{Taint};
122 no warnings 'uninitialized';
123 $ret = $sth->SUPER::execute(@_);
125 $sth->{Taint} = $old_value;