Better emulation of add_constructor, unfortunately also slower.
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / Constructor.pm
CommitLineData
c0e7b4e5 1package # hide from PAUSE
2 DBIx::Class::CDBICompat::Constructor;
a3018bd3 3
2e424e0c 4use base qw(DBIx::Class::CDBICompat::ImaDBI);
5
a3018bd3 6use strict;
7use warnings;
8
2e424e0c 9use Carp;
10
11__PACKAGE__->set_sql(Retrieve => <<'');
12SELECT __ESSENTIAL__
13FROM __TABLE__
14WHERE %s
15
a3018bd3 16sub add_constructor {
2e424e0c 17 my ($class, $method, $fragment) = @_;
18 return croak("constructors needs a name") unless $method;
19
20 no strict 'refs';
21 my $meth = "$class\::$method";
22 return carp("$method already exists in $class")
23 if *$meth{CODE};
24
25 *$meth = sub {
26 my $self = shift;
27 $self->sth_to_objects($self->sql_Retrieve($fragment), \@_);
a3018bd3 28 };
29}
30
311;