Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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/ line 214 at /usr/local/share/perl5/DBIx/Class/Result/ line 208 DBIx::Class::Result::Validation::__ANON__('Overhaul::DB::Schem +a::Result::track::Result: Validation faile...') called at /usr/local/ +share/perl5/Try/ 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/ 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/ line 2196 DBIx::Class::ResultSet::create('DBIx::Class::ResultSet=HASH(0x +1e3ad80)', 'HASH(0x1c4dcb8)') called at 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/ 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?

In reply to [more detail added] Trying to get DBIx::Class::Result::Validation to work by cLive ;-)

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    What's the matter? Cat got your tongue?...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (10)
    As of 2017-12-16 17:19 GMT
    Find Nodes?
      Voting Booth?
      What programming language do you hate the most?

      Results (457 votes). Check out past polls.