File Coverage

blib/lib/String/Normal.pm
Criterion Covered Total %
statement 27 28 96.4
branch 13 14 92.8
condition 2 3 66.6
subroutine 5 5 100.0
pod 2 2 100.0
total 49 52 94.2


line stmt bran cond sub pod time code
1             package String::Normal;
2 9     9   1371096 use strict;
  9         18  
  9         410  
3 9     9   46 use warnings;
  9         18  
  9         785  
4             our $VERSION = '0.08';
5              
6 9     9   4646 use String::Normal::Type;
  9         66  
  9         4043  
7              
8             sub new {
9 9     9 1 1603640 my $package = shift;
10 9         42 my $self = {@_};
11              
12 9 100 66     123 if (!$self->{type} or $self->{type} eq 'business') {
    100          
    100          
    100          
    100          
    100          
    50          
13 3         34 $self->{normalizer} = String::Normal::Type::Business->new( @_ );
14             } elsif ($self->{type} eq 'address') {
15 1         12 $self->{normalizer} = String::Normal::Type::Address->new( @_ );
16             } elsif ($self->{type} eq 'phone') {
17 1         13 $self->{normalizer} = String::Normal::Type::Phone->new( @_ );
18             } elsif ($self->{type} eq 'state') {
19 1         36 $self->{normalizer} = String::Normal::Type::State->new( @_ );
20             } elsif ($self->{type} eq 'city') {
21 1         13 $self->{normalizer} = String::Normal::Type::City->new( @_ );
22             } elsif ($self->{type} eq 'zip') {
23 1         8 $self->{normalizer} = String::Normal::Type::Zip->new( @_ );
24             } elsif ($self->{type} eq 'title') {
25 1         7 $self->{normalizer} = String::Normal::Type::Title->new( @_ );
26             } else {
27 0         0 die "type $self->{type} is not implemented\n";
28             }
29              
30 9         47 return bless $self, $package;
31             }
32              
33             # currently only handles business types
34             sub transform {
35 30     30 1 162 my ($self,$value,$type) = @_;
36              
37 30         77 $value = lc( $value ); # lowercase
38 30         80 $value =~ tr/ //s; # squeeze multiple spaces to one
39 30         92 $value =~ s/^ //; # trim leading space
40 30         66 $value =~ s/ $//; # trim trailing space
41              
42             # strip out control chars except tabs, lf's, cr's, r single quote, mdash and ndash
43 30         122 $value =~ s/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x91\x93-\x95\x98-\x9F]//g;
44              
45 30         168 return $self->{normalizer}->transform( $value );
46             }
47              
48             1;
49              
50             __END__