Replace many closure-based proxy methods with static qsubs
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / CDBICompat / Constructor.pm
CommitLineData
c0e7b4e5 1package # hide from PAUSE
2 DBIx::Class::CDBICompat::Constructor;
a3018bd3 3
4use strict;
5use warnings;
6
8d73fcd4 7use base 'DBIx::Class::CDBICompat::ImaDBI';
8
2e424e0c 9use Carp;
8d73fcd4 10use DBIx::Class::_Util qw(quote_sub perlstring);
2e424e0c 11
12__PACKAGE__->set_sql(Retrieve => <<'');
13SELECT __ESSENTIAL__
14FROM __TABLE__
15WHERE %s
16
a3018bd3 17sub add_constructor {
2e424e0c 18 my ($class, $method, $fragment) = @_;
2e424e0c 19
8d73fcd4 20 croak("constructors needs a name") unless $method;
21
22 carp("$method already exists in $class") && return
23 if $class->can($method);
2e424e0c 24
8d73fcd4 25 quote_sub "${class}::${method}" => sprintf( <<'EOC', perlstring $fragment );
26 my $self = shift;
27 $self->sth_to_objects($self->sql_Retrieve(%s), \@_);
28EOC
a3018bd3 29}
30
311;