Skip to content

Commit

Permalink
use a little less code
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 7, 2015
1 parent 0bfc963 commit 6a51c3e
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lib/Mojolicious/Validator/Validation.pm
Expand Up @@ -78,13 +78,12 @@ sub required {
sub _copy {
my ($self, $name, $all) = @_;

my $input = $self->input->{$name};
my @input = ref $input eq 'ARRAY' ? @$input : $input;
my @output = grep { defined && length } @input;
my $input = $self->input->{$name};
my @old = ref $input eq 'ARRAY' ? @$input : $input;
my @new = grep { defined && length } @old;

if ($all && @output && @input == @output) { $self->output->{$name} = $input }
elsif (!$all && @output > 1) { $self->output->{$name} = \@output }
elsif (!$all && @output) { $self->output->{$name} = $output[0] }
if ($all && @new && @old == @new) { $self->output->{$name} = $input }
elsif (!$all && @new) { $self->output->{$name} = @new > 1 ? \@new : $new[0] }

return $self->topic($name);
}
Expand Down

0 comments on commit 6a51c3e

Please sign in to comment.