| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package String::Normal; | 
| 2 | 9 |  |  | 9 |  | 182970 | use strict; | 
|  | 9 |  |  |  |  | 14 |  | 
|  | 9 |  |  |  |  | 225 |  | 
| 3 | 9 |  |  | 9 |  | 29 | use warnings; | 
|  | 9 |  |  |  |  | 9 |  | 
|  | 9 |  |  |  |  | 283 |  | 
| 4 |  |  |  |  |  |  | our $VERSION = '0.04'; | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 9 |  |  | 9 |  | 3033 | use String::Normal::Type; | 
|  | 9 |  |  |  |  | 36 |  | 
|  | 9 |  |  |  |  | 2084 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | sub new { | 
| 9 | 9 |  |  | 9 | 1 | 544923 | my $package = shift; | 
| 10 | 9 |  |  |  |  | 33 | my $self = {@_}; | 
| 11 |  |  |  |  |  |  |  | 
| 12 | 9 | 100 | 66 |  |  | 108 | if (!$self->{type} or $self->{type} eq 'business') { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 13 | 3 |  |  |  |  | 27 | $self->{normalizer} = String::Normal::Type::Business->new( @_ ); | 
| 14 |  |  |  |  |  |  | } elsif ($self->{type} eq 'address') { | 
| 15 | 1 |  |  |  |  | 8 | $self->{normalizer} = String::Normal::Type::Address->new( @_ ); | 
| 16 |  |  |  |  |  |  | } elsif ($self->{type} eq 'phone') { | 
| 17 | 1 |  |  |  |  | 9 | $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 |  |  |  |  | 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 |  |  |  |  | 35 | return bless $self, $package; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # currently only handles business types | 
| 34 |  |  |  |  |  |  | sub transform { | 
| 35 | 30 |  |  | 30 | 1 | 74 | my ($self,$value,$type) = @_; | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 30 |  |  |  |  | 70 | $value = lc( $value );      # lowercase | 
| 38 | 30 |  |  |  |  | 54 | $value =~ tr/  //s;         # squeeze multiple spaces to one | 
| 39 | 30 |  |  |  |  | 50 | $value =~ s/^ //;           # trim leading space | 
| 40 | 30 |  |  |  |  | 34 | $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 |  |  |  |  | 42 | $value =~ s/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x91\x93-\x95\x98-\x9F]//g; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 30 |  |  |  |  | 115 | return $self->{normalizer}->transform( $value ); | 
| 46 |  |  |  |  |  |  | } | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | 1; | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | __END__ |