Long story longer, the behavour of throw_exception changed in 0.08,
which broke DBIC::Validation::validate:

> sub validate {
>     my $self = shift;
>     my %data = $self->get_columns;
>     my $module = $self->validation_module;
>     my $profile = $self->validation_profile;
> 
>     if (ref $profile eq 'CODE') {
>         $profile = $profile->($self);
>     };
>     my $result = $module->check( \%data => $profile );
> 
>     if ($result->success) {
>         if ($self->validation_filter && $result->can('valid')) {
>             $self->$_($result->valid($_)) for ($result->valid);
>         };
>         return $result;
>     } else {
>         $self->throw_exception($result);
>     };
> };

Instead of die-ing with the object passed to it, it now wraps that
object in it's own DBIC::Exception. This broke the following
test/functionality:

> $row = eval{  $schema->resultset('Test')->create({name => ''}) };
> isa_ok $@, 'FormValidator::Simple::Results', 'blank value not accepted';

The easy fix for Validation was to simply croak($result) instead of
throw_exception($result):

> sub validate {
>     my $self = shift;
>     my %data = $self->get_columns;
>     my $module = $self->validation_module;
>     my $profile = $self->validation_profile;
> 
>     if (ref $profile eq 'CODE') {
>         $profile = $profile->($self);
>     };
>     my $result = $module->check( \%data => $profile );
> 
>     if ($result->success) {
>         if ($self->validation_filter && $result->can('valid')) {
>             $self->$_($result->valid($_)) for ($result->valid);
>         };
>         return $result;
>     } else {
>         croak $result;
>     };
> };

My question is, is that really the right thing to do? Should
throw_exception now wrap objects, but only wrap non-blessed strings?

This snafu also cropped up in Handel::Component::Validation, which is a
subclass of DBIC::Validation.  It used to override throw_exception to
wrap $results in a Validation Exception:

> sub throw_exception { ## no critic (RequireFinalReturn)
>     my ($self, $exception) = @_;
> 
>     if (blessed $exception) {
>         $self->next::method(
>             Handel::Exception::Validation->new(-results => $exception)
>         );
>     } else {
>         $self->next::method(
>             Handel::Exception::Validation->new(-details => $exception)
>         );
>     };
> };

Now that Validation/throw_exception has changed, I've had to do this in
addition to my custom throw_exception:

> sub validate {
>     my $self = shift;
>     my $result;
> 
>     eval {
>         $result = $self->next::method(@_);
>     };
>     if ($@) {
>         $self->throw_exception($@);
>     };
> 
>     return $result;
> };

It all seems a bit obtuse. Maybe it's nothing and everything is just
dandy. Thoughts?

-=Chris

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/dbix-class@lists.rawmode.org/

Reply via email to