Last night I was wiped, but here's an expanded version...
I wrote a standlone, minimal example, after reading this discussion (about the only one I could find on the module).
#!/usr/bin/perl
use strict;
use Overhaul::DB;
my $dbx = Overhaul::DB->new('track');
my $schema = $dbx->schema;
# this works as expected
my $valid_result = $schema->resultset('track::Result')->create({
first_name => 'Clive',
last_name => 'Testing',
});
$valid_result->delete;
my $bad_result = try { $schema->resultset('track::Result')->create({
last_name => 'Testing',
});
} catch { $_ };
print "**************** We made it to here\n";
When I run it though, it dumps the error:
Overhaul::DB::Schema::Result::track::Result: Validation failed.
{
'first_name' => [
'First name is required'
]
}
(yay, I wanted that). But then it dumps a stack trace and quits. Am I meant to overload the DBIx::Class exception handler?
at /usr/local/share/perl5/DBIx/Class/Result/Validation.pm line 214
at /usr/local/share/perl5/DBIx/Class/Result/Validation.pm line 208
DBIx::Class::Result::Validation::__ANON__('Overhaul::DB::Schem
+a::Result::track::Result: Validation faile...') called at /usr/local/
+share/perl5/Try/Tiny.pm line 100
Try::Tiny::try('CODE(0x1e3ab10)', 'Try::Tiny::Catch=REF(0x1933
+640)') called at /usr/local/share/perl5/DBIx/Class/Result/Validation.
+pm line 214
DBIx::Class::Result::Validation::_try_next_method('Overhaul::D
+B::Schema::Result::track::Result=HASH(0x1e3ad98)', 'CODE(0xc591f0)',
+undef) called at /usr/local/share/perl5/DBIx/Class/Result/Validation.
+pm line 169
DBIx::Class::Result::Validation::insert('Overhaul::DB::Schema:
+:Result::track::Result=HASH(0x1e3ad98)', undef) called at Overhaul/DB
+/Schema/Result/track/Result.pm line 62
Overhaul::DB::Schema::Result::track::Result::insert('Overhaul:
+:DB::Schema::Result::track::Result=HASH(0x1e3ad98)') called at /usr/s
+hare/perl5/DBIx/Class/ResultSet.pm line 2196
DBIx::Class::ResultSet::create('DBIx::Class::ResultSet=HASH(0x
+1e3ad80)', 'HASH(0x1c4dcb8)') called at tmp.pl line 18
When I switch it out to an eval, it works:
my $bad_result;
eval {
$bad_result = $schema->resultset('track::Result')->create({
last_name => 'Testing',
});
};
$@ contains:
Create failed: Overhaul::DB::Schema::Result::track::Result: Validatio
+n failed.
{
'first_name' => [
'First name is required'
]
}
at /usr/local/share/perl5/DBIx/Class/Result/Validation.pm line 214
However, I still can't work out how to get to the error data (I'm guessing the module author is French, with limited English, so the docs are not that clear).
I think I'm missing something on the paradigm shift from plain DBI to DBIx::Class. In DBI, say the error was at the data level (wrong type, say), it would throw you like this (from the DB rather than internal validation):
$sth->execute || die "Query failed"
So, to sum up, I think it's two questions. What am I missing here? Is this the best way to run DBIx::Class data validation, or should I be using a different approach?