恒例のプラグイン化

すげー適当ですが、つくてみますた。


package Class::DBI::Plugin::DeleteFast;
use strict;
use warnings;
use vars qw($VERSION @EXPORT);
require Exporter;
@EXPORT = qw(delete_fast);
$VERSION = 0.01;
use SQL::Abstract;
sub import {
my $pkg = caller(0);
$pkg->mk_classdata('_delete_fast');
goto &Exporter::import;
}
sub delete_fast {
my $class = shift;
my $where = (ref $_[0]) ? $_[0] : { @_ };
unless ( $class->_delete_fast ){
$class->_delete_fast(SQL::Abstract->new);
}
my ($stmt, @bind) = $class->_delete_fast->delete($class->table,$where);
my $sth;
eval { $sth = $class->db_Main->prepare($stmt) };
if ($@) {
return $class->_db_error(
msg => "Can't delete $class: $@",
err => $@,
method => 'delete_fast',
);
}
eval { $sth->execute(@bind) };
if ($@) {
return $class->_db_error(
msg => "Can't delete $class: $@",
err => $@,
method => 'delete_fast',
);
}
return 1;
}
1;

ってか、こういうのって既に提供されてたりしないのですかねぇ?