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   20464 use strict;
  1         2  
  1         106  
4 1     1   10 use warnings;
  1         1  
  1         53  
5 1     1   8 use vars qw(@ISA $VERSION @EXPORT_OK);
  1         2  
  1         107  
6 1     1   658 use Business::DK::Postalcode qw(validate);
  1         2  
  1         110  
7 1     1   8 use Scalar::Util qw(blessed);
  1         1  
  1         47  
8 1     1   5 use Carp qw(croak);
  1         1  
  1         58  
9              
10 1     1   5 use base 'Exporter';
  1         1  
  1         102  
11              
12             @EXPORT_OK
13             = qw(valid_postalcode match_postalcode postalcode danish_postalcode postalcode_denmark);
14              
15 1     1   4 use constant INVALID => undef;
  1         2  
  1         283  
16              
17             our $VERSION = '0.11';
18              
19             sub postalcode {
20             return sub {
21 3     3   1938 return match_postalcode(@_);
22             }
23 3     3 1 7469 }
24              
25             sub valid_postalcode {
26             return sub {
27 6     6   4196 return match_postalcode(@_);
28             }
29 6     6 1 13945 }
30              
31             sub match_postalcode {
32 9     9 1 12 my $dfv = shift;
33              
34 9 100       35 my $postalcode = ref $dfv ? $dfv->get_current_constraint_value : $dfv;
35              
36 9 100       42 if ( ref $dfv ) {
37 7         17 $dfv->name_this('match_postalcode');
38             }
39              
40 9 100       40 if ( my $untainted_postalcode = validate($postalcode) ) {
41 7 100       17 if ( ref $dfv ) {
42 6         15 $dfv->untainted_constraint_value($untainted_postalcode);
43             }
44              
45 7         43 return $untainted_postalcode;
46             } else {
47 2         9 return INVALID;
48             }
49             }
50              
51             1;
52              
53             __END__