Skip to content

Instantly share code, notes, and snippets.

@riywo
Created January 31, 2012 13:57
Show Gist options
  • Save riywo/1710616 to your computer and use it in GitHub Desktop.
Save riywo/1710616 to your computer and use it in GitHub Desktop.
Amon2::Plugin::DBIx::Handler
use strict;
use warnings;
use utf8;
package Amon2::Plugin::DBIx::Handler;
use DBIx::Handler;
sub init {
my ($class, $context_class, $config) = @_;
no strict 'refs';
*{"$context_class\::handler"} = \&_handler;
}
sub _handler {
my ($self) = @_;
if ( !defined $self->{handler} ) {
my $conf = $self->config->{'DBI'}
or die "missing configuration for 'DBI'";
$self->{handler} = DBIx::Handler->new(@$conf);
}
return $self->{handler};
}
1;
__END__
in app.psgi or etc
__PACKAGE__->load_plugin('DBIx::Handler');
my $txn = $c->handler->txn_scope;
# ここでトランザクションを効かせたい処理を行う
$c->handler->dbh->do('insert...');
$txn->commit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment