Skip to content

Commit

Permalink
Distinguish cases when widget don't exists and other errors
Browse files Browse the repository at this point in the history
When a custom widget contains compile errors, the user sees them.
And the error "Can't find widget..." will receive only if the
widget is really missing.
  • Loading branch information
Vladimir Timofeev authored and gshank committed Apr 26, 2010
1 parent b196fff commit 214ba05
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions lib/HTML/FormHandler/Widget/ApplyRole.pm
Expand Up @@ -3,6 +3,7 @@ package HTML::FormHandler::Widget::ApplyRole;
use Moose::Role;
use File::Spec;
use Class::MOP;
use Try::Tiny;

our $ERROR;

Expand All @@ -21,11 +22,10 @@ sub get_widget_role {
('HTML::FormHandler::Widget', 'HTML::FormHandlerX::Widget') );
foreach my $ns (@name_spaces) {
my $render_role = $ns . $ldir . $widget_class;
if ( eval { Class::MOP::load_class($render_role) } ) {
return $render_role;
}
try { Class::MOP::load_class($render_role) } catch { die $_ unless $_ =~ /^Can't locate/; };
return $render_role if Class::MOP::is_class_loaded($render_role);
}
die "not able to load $dir widget $widget_class from " . join(", ", @name_spaces);
die "Can't find $dir widget $widget_class from " . join(", ", @name_spaces);
}

# this is for compatibility with widget names like 'radio_group'
Expand Down
2 changes: 1 addition & 1 deletion t/render_widgets.t
Expand Up @@ -264,7 +264,7 @@ is( $form->field('omega')->render, '<h1>You got here!</h1>', 'omega rendered
has_field 'no_widget' => ( widget => 'no_widget' );
}
dies_ok( sub { Test::NoWidget->new }, 'dies on no widget' );
throws_ok( sub { Test::NoWidget->new }, qr/not able to load/, 'no widget throws message' );
throws_ok( sub { Test::NoWidget->new }, qr/Can't find /, 'no widget throws message' );

$form = Test::Form->new( widget_form => 'Table', widget_wrapper => 'Table' );
ok( $form->can('render'), 'form has table widget' );
Expand Down

0 comments on commit 214ba05

Please sign in to comment.