| 1 | package String::Normal; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use String::Normal::Type; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 9 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 9 | my $package = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 9 | my $self = {@_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 9 | ▶ | if (!$self->{type} or $self->{type} eq 'business') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
Condition66%2/3
not $self->{"type"} or $self->{"type"} eq "business"
MC/DC50%1/2
not $self->{"type"} or $self->{"type"} eq "business"
not $self->{"type"}
$self->{"type"} eq "business"
Truth table66%2/3
not(A) or B
A= not $self->{"type"}B= $self->{"type"} eq "business"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | $self->{normalizer} = String::Normal::Type::Business->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | } elsif ($self->{type} eq 'address') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | $self->{normalizer} = String::Normal::Type::Address->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | } elsif ($self->{type} eq 'phone') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | $self->{normalizer} = String::Normal::Type::Phone->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } elsif ($self->{type} eq 'state') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | $self->{normalizer} = String::Normal::Type::State->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } elsif ($self->{type} eq 'city') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | $self->{normalizer} = String::Normal::Type::City->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | } elsif ($self->{type} eq 'zip') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | $self->{normalizer} = String::Normal::Type::Zip->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | } elsif ($self->{type} eq 'title') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | $self->{normalizer} = String::Normal::Type::Title->new( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | die "type $self->{type} is not implemented\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 9 | return bless $self, $package; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # currently only handles business types | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 30 | ▶ | sub transform { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
transform: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 30 | my ($self,$value,$type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 30 | $value = lc( $value ); # lowercase | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 30 | $value =~ tr/ //s; # squeeze multiple spaces to one | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 30 | $value =~ s/^ //; # trim leading space | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 30 | $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 | $value =~ s/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x91\x93-\x95\x98-\x9F]//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 30 | return $self->{normalizer}->transform( $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||