Skip to content

Commit

Permalink
Instead of suppressing an exception, prevent it (#148)
Browse files Browse the repository at this point in the history
By checking if the dereferenced value is blessed, make sure we can
call 'isa' on it. Adds dependency on `Scalar::Util` (which is in 'core').
  • Loading branch information
ehuelsmann committed Jul 30, 2021
1 parent b4ddebb commit fb7b31e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions dist.ini
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Data::Dumper = 0
Carp = 0
File::Slurp = 0
Data::UUID = 0
Scalar::Util = 0

; REF: Dist::Zilla https://metacpan.org/pod/Dist::Zilla
[Prereqs / TestRequires]
Expand Down
9 changes: 4 additions & 5 deletions lib/Workflow/Validator/MatchesDateFormat.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use strict;
use base qw( Workflow::Validator );
use DateTime::Format::Strptime;
use Workflow::Exception qw( configuration_error validation_error );
use English qw( -no_match_vars );
use Carp qw(carp);
use Scalar::Util qw( blessed );

$Workflow::Validator::MatchesDateFormat::VERSION = '1.56';

Expand Down Expand Up @@ -34,12 +34,11 @@ sub validate {
my ( $self, $wf, $date_string ) = @_;
return unless ($date_string);

# already converted!
if ( ref $date_string and eval { $date_string->isa('DateTime'); } ) {
if ( blessed $date_string and $date_string->isa('DateTime') ) {
# already converted!
return;
}

if ($EVAL_ERROR) {
if ( ref $date_string ) { # ref but not blessed?!

This comment has been minimized.

Copy link
@ehuelsmann

ehuelsmann Jul 31, 2021

Author Member

@jonasbn Due to this branch of the if being "carp" and not "croak", the ill-understood value is passed to the date-time parser. Should we either not check, or croak? (both resulting in errors anyway).

carp 'Unable to assert DateTime or similar object';
}

Expand Down

0 comments on commit fb7b31e

Please sign in to comment.