my
$schema
= DBICTest->init_schema;
my
$throw
=
sub
{
$schema
->resultset(
"Artist"
)->search(1,1,1) };
my
$ex_regex
=
qr/Odd number of arguments to search/
;
throws_ok \
&$throw
,
$ex_regex
;
my
$e
= $@;
throws_ok {
$e
->rethrow }
$ex_regex
;
isa_ok( $@,
'DBIx::Class::Exception'
);
$schema
->exception_action(
sub
{
die
@_
});
throws_ok \
&$throw
,
$ex_regex
;
$schema
->exception_action(
sub
{ 1 });
throws_ok \
&$throw
,
qr/exception_action handler .+ did \*not\* result in an exception.+original error: $ex_regex/
;
$schema
->exception_action(
sub
{
return
});
throws_ok {
warnings_are \
&$throw
,
qr/exception_action handler installed .+ returned false instead throwing an exception/
;
}
$ex_regex
;
throws_ok {
warnings_are \
&$throw
,
[];
}
$ex_regex
;
{
use
overload
'""'
=> \
&stringify
,
fallback
=> 1;
sub
new {
my
$class
=
shift
;
bless
{
msg
=>
shift
},
$class
;
}
sub
throw {
my
$self
=
shift
;
die
$self
if
ref
$self
eq __PACKAGE__;
die
$self
->new(
shift
);
}
sub
stringify {
"DBICTest::Exception is handling this: "
.
shift
->{msg};
}
}
$schema
->exception_action(
sub
{ DBICTest::Exception->throw(
@_
) });
throws_ok \
&$throw
,
qr/DBICTest::Exception is handling this: $ex_regex/
;
throws_ok {
$schema
->storage->throw_exception(
'floob'
) }
qr/DBICTest::Exception is handling this: floob/
;
done_testing;