X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FCDBICompat%2FConstructor.pm;h=f2e78b9251aa0193b7278d0e35d4809fd76200dc;hb=7664b1a03c8f4da961d1f9795c9af1d545a24ea1;hp=407722497bfdfbbaa9ec16650b1ff8bfc8894ed1;hpb=c0e7b4e55952cd193b6f1866d0c27ece182397eb;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/CDBICompat/Constructor.pm b/lib/DBIx/Class/CDBICompat/Constructor.pm index 4077224..f2e78b9 100644 --- a/lib/DBIx/Class/CDBICompat/Constructor.pm +++ b/lib/DBIx/Class/CDBICompat/Constructor.pm @@ -1,17 +1,32 @@ package # hide from PAUSE DBIx::Class::CDBICompat::Constructor; +use base qw(DBIx::Class::CDBICompat::ImaDBI); + +use Sub::Name(); + use strict; use warnings; +use Carp; + +__PACKAGE__->set_sql(Retrieve => <<''); +SELECT __ESSENTIAL__ +FROM __TABLE__ +WHERE %s + sub add_constructor { - my ($class, $meth, $sql) = @_; - $class = ref $class if ref $class; - no strict 'refs'; - *{"${class}::${meth}"} = - sub { - my ($class, @args) = @_; - return $class->search_literal($sql, @args); + my ($class, $method, $fragment) = @_; + return croak("constructors needs a name") unless $method; + + no strict 'refs'; + my $meth = "$class\::$method"; + return carp("$method already exists in $class") + if *$meth{CODE}; + + *$meth = Sub::Name::subname $meth => sub { + my $self = shift; + $self->sth_to_objects($self->sql_Retrieve($fragment), \@_); }; }