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   188393 use strict;
  9         13  
  9         213  
3 9     9   28 use warnings;
  9         10  
  9         310  
4             our $VERSION = '0.06';
5              
6 9     9   3114 use String::Normal::Type;
  9         14  
  9         2194  
7              
8             sub new {
9 9     9 1 546067 my $package = shift;
10 9         32 my $self = {@_};
11              
12 9 100 66     111 if (!$self->{type} or $self->{type} eq 'business') {
    100          
    100          
    100          
    100          
    100          
    50          
13 3         25 $self->{normalizer} = String::Normal::Type::Business->new( @_ );
14             } elsif ($self->{type} eq 'address') {
15 1         6 $self->{normalizer} = String::Normal::Type::Address->new( @_ );
16             } elsif ($self->{type} eq 'phone') {
17 1         7 $self->{normalizer} = String::Normal::Type::Phone->new( @_ );
18             } elsif ($self->{type} eq 'state') {
19 1         8 $self->{normalizer} = String::Normal::Type::State->new( @_ );
20             } elsif ($self->{type} eq 'city') {
21 1         8 $self->{normalizer} = String::Normal::Type::City->new( @_ );
22             } elsif ($self->{type} eq 'zip') {
23 1         7 $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         35 return bless $self, $package;
31             }
32              
33             # currently only handles business types
34             sub transform {
35 30     30 1 80 my ($self,$value,$type) = @_;
36              
37 30         53 $value = lc( $value ); # lowercase
38 30         59 $value =~ tr/ //s; # squeeze multiple spaces to one
39 30         48 $value =~ s/^ //; # trim leading space
40 30         38 $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         43 $value =~ s/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x91\x93-\x95\x98-\x9F]//g;
44              
45 30         116 return $self->{normalizer}->transform( $value );
46             }
47              
48             1;
49              
50             __END__