File Coverage

lib/CGI/ValidOp/Check/required_if.pm
Criterion Covered Total %
statement 17 17 100.0
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 26 27 96.3


line stmt bran cond sub pod time code
1             package CGI::ValidOp::Check::required_if;
2              
3 1     1   6 use strict;
  1         2  
  1         37  
4 1     1   6 use warnings;
  1         3  
  1         46  
5              
6 1     1   5 use base qw/ CGI::ValidOp::Check /;
  1         2  
  1         487  
7              
8             sub default {
9 4     4 0 6 my $self = shift;
10             sub {
11 4     4   10 my ( $value, $cond ) = @_;
12              
13             # pass if both are set OR if both are unset
14             # see caveats in Check::alternative too
15 4         18 my $cgi = CGI->new;
16 4 100       5276 return $self->pass unless $cgi->param( $cond );
17 2 100       68 return $self->fail( "\$label is required." ) unless $value;
18 1         5 $value =~ m/^(.*)$/;
19 1         6 return $self->pass( "$1" );
20 4         22 };
21             }
22              
23             1;