File Coverage

lib/Data/FormValidator/Constraints/Business/DK/Postalcode.pm
Criterion Covered Total %
statement 37 37 100.0
branch 8 8 100.0
condition n/a
subroutine 13 13 100.0
pod 3 3 100.0
total 61 61 100.0


line stmt bran cond sub pod time code
1             package Data::FormValidator::Constraints::Business::DK::Postalcode;
2              
3 1     1   5610 use strict;
  1         2  
  1         31  
4 1     1   4 use warnings;
  1         2  
  1         28  
5 1     1   5 use vars qw(@ISA $VERSION @EXPORT_OK);
  1         2  
  1         65  
6 1     1   569 use Business::DK::Postalcode qw(validate);
  1         2  
  1         72  
7 1     1   7 use Scalar::Util qw(blessed);
  1         2  
  1         45  
8 1     1   6 use Carp qw(croak);
  1         2  
  1         38  
9              
10 1     1   4 use base 'Exporter';
  1         2  
  1         90  
11              
12             @EXPORT_OK
13             = qw(valid_postalcode match_postalcode postalcode danish_postalcode postalcode_denmark);
14              
15 1     1   7 use constant INVALID => undef;
  1         2  
  1         260  
16              
17             our $VERSION = '0.11';
18              
19             sub postalcode {
20             return sub {
21 3     3   2587 return match_postalcode(@_);
22             }
23 3     3 1 12392 }
24              
25             sub valid_postalcode {
26             return sub {
27 6     6   5562 return match_postalcode(@_);
28             }
29 6     6 1 22842 }
30              
31             sub match_postalcode {
32 9     9 1 19 my $dfv = shift;
33              
34 9 100       43 my $postalcode = ref $dfv ? $dfv->get_current_constraint_value : $dfv;
35              
36 9 100       66 if ( ref $dfv ) {
37 7         25 $dfv->name_this('match_postalcode');
38             }
39              
40 9 100       71 if ( my $untainted_postalcode = validate($postalcode) ) {
41 7 100       24 if ( ref $dfv ) {
42 6         24 $dfv->untainted_constraint_value($untainted_postalcode);
43             }
44              
45 7         70 return $untainted_postalcode;
46             } else {
47 2         10 return INVALID;
48             }
49             }
50              
51             1;
52              
53             __END__