DBIのRootClassを使うとScope::Container::DBIで接続を管理しつつ、Amon2::DBIが使えます。
#!/usr/bin/env perl
use strict;
use warnings;
use 5.12.0;
use Scope::Container::DBI;
my $dbh = Scope::Container::DBI->connect(
'dbi:SQLite::memory:', '', '',
{ RootClass => 'Amon2::DBI' }
);
$dbh->do(q{CREATE TABLE foo (e)});
$dbh->insert('foo', {e => 3});
$dbh->do_i('INSERT INTO foo ', {e => 4});
say join(',', map { @$_ } @{$dbh->selectall_arrayref('SELECT * FROM foo ORDER BY e')});
eval {
$dbh->insert('bar', {e => 3});
};
say $@;
Amon2を使うと、utf8の自動設定やエラー処理、Nested Transaction、DBIx::Interpをつかったクエリ生成がサポートされるので便利ですね