| 1 | #=============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # FILE: Games::Go::AGA::Parse::TDList.pm | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # PODNAME: Games::Go::AGA::Parse::TDList | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Parses lines from an AGA TDLISTlist | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # AUTHOR: Reid Augustin (REID), <reid@lucidport.com> | ||||||||||||||||||||||||||||||||||||||||||
| 9 | # COMPANY: LucidPort Technology, Inc. | ||||||||||||||||||||||||||||||||||||||||||
| 10 | # CREATED: Tue Jan 18 16:12:35 PST 2011 | ||||||||||||||||||||||||||||||||||||||||||
| 11 | #=============================================================================== | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | package Games::Go::AGA::Parse::TDList; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use parent 'Games::Go::AGA::Parse'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | use String::Tokenizer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use Scalar::Util qw( looks_like_number ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | ▶ | use Games::Go::AGA::Parse::Util qw( is_Rating is_Rank_or_Rating normalize_ID ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 1 | ▶ | use Games::Go::AGA::Parse::Exceptions; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | our $VERSION = '0.042'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | ▶ | sub last_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
last_name: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 9 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 9 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | $self->{last_name} = $new; | |||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 9 | ▶ | return $self->{last_name} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'last_name'} || ''
MC/DC0%0/1
$self->{'last_name'} || ''
$self->{'last_name'}
Truth table50%1/2
A
A= $self->{'last_name'}
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 9 | ▶ | sub first_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
first_name: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 9 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 9 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | $self->{first_name} = $new; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 9 | ▶ | return $self->{first_name} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'first_name'} || ''
MC/DC100%1/1
$self->{'first_name'} || ''
$self->{'first_name'}
Truth table100%2/2
A
A= $self->{'first_name'}
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 9 | ▶ | sub id { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
id: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 9 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 9 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $self->{id} = $new; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 9 | ▶ | return $self->{id} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'id'} || ''
MC/DC100%1/1
$self->{'id'} || ''
$self->{'id'}
Truth table100%2/2
A
A= $self->{'id'}
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | ▶ | sub membership { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
membership: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 9 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 9 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $self->{membership} = $new; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 9 | ▶ | return $self->{membership} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'membership'} || ''
MC/DC100%1/1
$self->{'membership'} || ''
$self->{'membership'}
Truth table100%2/2
A
A= $self->{'membership'}
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 27 | ▶ | sub rank { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rank: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 27 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 27 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 9 | $self->{rank} = $new; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 9 | ▶ | $self->{rank} += 0 if (is_Rating($new)); # numify | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 27 | ▶ | return $self->{rank} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'rank'} || ''
MC/DC100%1/1
$self->{'rank'} || ''
$self->{'rank'}
Truth table100%2/2
A
A= $self->{'rank'}
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 9 | ▶ | sub date { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
date: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 9 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 9 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $self->{date} = $new; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 9 | ▶ | return $self->{date} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'date'} || ''
MC/DC100%1/1
$self->{'date'} || ''
$self->{'date'}
Truth table100%2/2
A
A= $self->{'date'}
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 9 | ▶ | sub club { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
club: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 9 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 9 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $self->{club} = $new; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 9 | ▶ | return $self->{club} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'club'} || ''
MC/DC100%1/1
$self->{'club'} || ''
$self->{'club'}
Truth table100%2/2
A
A= $self->{'club'}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 9 | ▶ | sub state { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
state: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 9 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 9 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->{state} = $new; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 9 | ▶ | return $self->{state} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{'state'} || ''
MC/DC100%1/1
$self->{'state'} || ''
$self->{'state'}
Truth table100%2/2
A
A= $self->{'state'}
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 9 | ▶ | sub extra { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extra: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | 9 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 9 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $self->{extra} = $new; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 9 | ▶ | return $self->{extra} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'extra'} || ''
MC/DC0%0/1
$self->{'extra'} || ''
$self->{'extra'}
Truth table50%1/2
A
A= $self->{'extra'}
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub as_array { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_array: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | my @ret = map | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | { $self->$_ } | |||||||||||||||||||||||||||||||||||||||||
| 116 | # fields, in order | ||||||||||||||||||||||||||||||||||||||||||
| 117 | qw( | ||||||||||||||||||||||||||||||||||||||||||
| 118 | last_name | ||||||||||||||||||||||||||||||||||||||||||
| 119 | first_name | ||||||||||||||||||||||||||||||||||||||||||
| 120 | id | ||||||||||||||||||||||||||||||||||||||||||
| 121 | membership | ||||||||||||||||||||||||||||||||||||||||||
| 122 | rank | ||||||||||||||||||||||||||||||||||||||||||
| 123 | date | ||||||||||||||||||||||||||||||||||||||||||
| 124 | club | ||||||||||||||||||||||||||||||||||||||||||
| 125 | state | ||||||||||||||||||||||||||||||||||||||||||
| 126 | extra | ||||||||||||||||||||||||||||||||||||||||||
| 127 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | return wantarray ? @ret : \@ret; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 9 | ▶ | sub as_hash { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_hash: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 9 | my ($self, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | my %ret = map | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 9 | { $_, $self->$_ } | |||||||||||||||||||||||||||||||||||||||||
| 136 | # fields | ||||||||||||||||||||||||||||||||||||||||||
| 137 | qw( | ||||||||||||||||||||||||||||||||||||||||||
| 138 | last_name | ||||||||||||||||||||||||||||||||||||||||||
| 139 | first_name | ||||||||||||||||||||||||||||||||||||||||||
| 140 | id | ||||||||||||||||||||||||||||||||||||||||||
| 141 | membership | ||||||||||||||||||||||||||||||||||||||||||
| 142 | rank | ||||||||||||||||||||||||||||||||||||||||||
| 143 | date | ||||||||||||||||||||||||||||||||||||||||||
| 144 | club | ||||||||||||||||||||||||||||||||||||||||||
| 145 | state | ||||||||||||||||||||||||||||||||||||||||||
| 146 | extra | ||||||||||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 9 | ▶ | return wantarray ? %ret : \%ret; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | Readonly my $LAST_NAME => 0; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | Readonly my $FIRST_NAME => 1; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | Readonly my $ID => 2; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | Readonly my $MEMBERSHIP => 3; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | Readonly my $RANK => 4; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | Readonly my $DATE => 5; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | Readonly my $CLUB => 6; | |||||||||||||||||||||||||||||||||||||||||
| 158 | 1 | Readonly my $STATE => 7; | |||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | Readonly my $EXTRA => 8; | |||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | Readonly my %name_of_state => ( | |||||||||||||||||||||||||||||||||||||||||
| 162 | $FIRST_NAME => 'first_name', | ||||||||||||||||||||||||||||||||||||||||||
| 163 | $ID => 'id', | ||||||||||||||||||||||||||||||||||||||||||
| 164 | $MEMBERSHIP => 'membership', | ||||||||||||||||||||||||||||||||||||||||||
| 165 | $RANK => 'rank', | ||||||||||||||||||||||||||||||||||||||||||
| 166 | $DATE => 'date', | ||||||||||||||||||||||||||||||||||||||||||
| 167 | $CLUB => 'club', | ||||||||||||||||||||||||||||||||||||||||||
| 168 | $STATE => 'state', | ||||||||||||||||||||||||||||||||||||||||||
| 169 | $EXTRA => 'extra', | ||||||||||||||||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | Readonly my %MEMBERSHIP_TYPES => ( | |||||||||||||||||||||||||||||||||||||||||
| 173 | Full => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 174 | Youth => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 175 | Limit => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 176 | Non => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 177 | Sust => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 178 | Spons => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 179 | Forgn => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 180 | Comp => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 181 | Life => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 182 | Donar => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | Readonly my %state_functions => ( | ||||||||||||||||||||||||||||||||||||||||||
| 186 | 24 | ▶ | $LAST_NAME => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | 24 | my ($self, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 24 | ▶ | if ($token eq ',') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 11 | return $FIRST_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 13 | ▶ | if ($token =~ m/^\w*\d+$/ and # IDs are numbers with possible alpha prefix | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$token =~ /^\w*\d+$/ and @{$self->{"last_name"};}
MC/DC50%1/2
$token =~ /^\w*\d+$/ and @{$self->{"last_name"};}
$token =~ /^\w*\d+$/
@{$self->{"last_name"};}
Truth table66%2/3
A and B
A= $token =~ /^\w*\d+$/B= @{$self->{"last_name"};}
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | @{$self->{last_name}}) { # but only if we already have a name | |||||||||||||||||||||||||||||||||||||||||
| 194 | 1 | $self->{id} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 195 | 1 | return $MEMBERSHIP; | |||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 12 | push @{$self->{last_name}}, $token; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 12 | return $LAST_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 199 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 25 | ▶ | $FIRST_NAME => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 25 | my ($self, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 25 | ▶ | if ($token eq ',') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | # Oops. transfer anything we saved in first_name back to | ||||||||||||||||||||||||||||||||||||||||||
| 205 | # last_name | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | push @{$self->{last_name}}, @{$self->{first_name}}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $self->{first_name} = []; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | return $FIRST_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 25 | ▶ | if ($token =~ m/^\w*\d+$/) { # IDs are numbers with possible alpha prefix | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 8 | $self->{id} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 212 | 8 | return $MEMBERSHIP; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 17 | ▶ | if (exists $MEMBERSHIP_TYPES{$token}) { # skipped over ID? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 215 | 2 | $self->{membership} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | return $RANK; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | 15 | ▶ | if (is_Rank_or_Rating($token)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | Games::Go::AGA::Parse::Exception->throw( | ||||||||||||||||||||||||||||||||||||||||||
| 220 | error => "Invalid membership", | ||||||||||||||||||||||||||||||||||||||||||
| 221 | filename => 'fake_file', | ||||||||||||||||||||||||||||||||||||||||||
| 222 | source => $self->{source}, | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | line_number => 321, | |||||||||||||||||||||||||||||||||||||||||
| 224 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 14 | push @{$self->{first_name}}, $token; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 14 | return $FIRST_NAME; # first name may have several parts | |||||||||||||||||||||||||||||||||||||||||
| 228 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | ▶ | $ID => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my ($self, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | if (exists $MEMBERSHIP_TYPES{$token}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $self->{membership} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return $RANK; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $self->{id} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | return $MEMBERSHIP; | |||||||||||||||||||||||||||||||||||||||||
| 238 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 9 | ▶ | $MEMBERSHIP => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=17.6
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 9 | my ($self, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 9 | ▶ | if ($token eq ',') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | # Oops. We got here because something looked like an ID | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # but was really part of the last name. transfer | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # anything we saved in first_name and id back to last_name | ||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | push @{$self->{last_name}}, @{$self->{first_name}}, $self->{id}; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $self->{first_name} = []; | |||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | $self->{id} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return $FIRST_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 9 | ▶ | if (not exists $MEMBERSHIP_TYPES{$token}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 2 | ▶ | if ($token eq '0.0' or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$token eq "0.0" or is_Rank_or_Rating($token)
MC/DC50%1/2
$token eq "0.0" or is_Rank_or_Rating($token)
$token eq "0.0"
is_Rank_or_Rating($token)
Truth table66%2/3
A or B
A= $token eq "0.0"B= is_Rank_or_Rating($token)
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | is_Rank_or_Rating($token)) { | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 1 | $self->{membership} = ''; # shrug | |||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | $self->rank($token); | |||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | return $DATE; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | $self->_parse_error( | ||||||||||||||||||||||||||||||||||||||||||
| 259 | error => "Invalid membership: $token", | ||||||||||||||||||||||||||||||||||||||||||
| 260 | source => $self->{source}, | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 7 | $self->{membership} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 7 | return $RANK; | |||||||||||||||||||||||||||||||||||||||||
| 265 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 9 | ▶ | $RANK => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 9 | my ($self, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 9 | ▶ | if ($token eq '0.0' or | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$token eq "0.0" or is_Rank_or_Rating($token)
MC/DC50%1/2
$token eq "0.0" or is_Rank_or_Rating($token)
$token eq "0.0"
is_Rank_or_Rating($token)
Truth table66%2/3
A or B
A= $token eq "0.0"B= is_Rank_or_Rating($token)
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | is_Rank_or_Rating($token)) { | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 7 | $self->rank($token); | |||||||||||||||||||||||||||||||||||||||||
| 272 | 7 | return $DATE; | |||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | # grrr: AGA changed the format; rank can be blank or 0.0 | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 2 | ▶ | if ($token =~ m/^\d\d?\/\d\d?\/\d{2,4}$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 1 | $self->rank(0); | |||||||||||||||||||||||||||||||||||||||||
| 277 | 1 | $self->{date} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | return $CLUB; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | $self->_parse_error( | ||||||||||||||||||||||||||||||||||||||||||
| 281 | error => "Invalid rank $token", | ||||||||||||||||||||||||||||||||||||||||||
| 282 | source => $self->{source}, | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 284 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 8 | ▶ | $DATE => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 8 | my ($self, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 8 | ▶ | if ($token =~ m/^\d\d?\D\d\d?\D\d{2,4}$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | 6 | $self->{date} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 6 | return $CLUB; | |||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | 2 | ▶ | if ($token =~ m/^[A-Z][A-Z]$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $self->{state} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | return $EXTRA; | |||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 2 | $self->{club} = $token; # shrug - best guess is this is a club | |||||||||||||||||||||||||||||||||||||||||
| 297 | 2 | return $STATE; | |||||||||||||||||||||||||||||||||||||||||
| 298 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 299 | 7 | ▶ | $CLUB => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 7 | my ($self, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 7 | ▶ | if ($token =~ m/^[A-Z][A-Z]$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | $self->{state} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 304 | 1 | return $EXTRA; | |||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 6 | $self->{club} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 6 | return $STATE; | |||||||||||||||||||||||||||||||||||||||||
| 308 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 309 | 7 | ▶ | $STATE => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=17.3
| |||||||||||||||||||||||||||||||||||||||||||
| 310 | 7 | my ($self, $token) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 7 | ▶ | if (($token eq '-') and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$token eq "-" and $self->{"state"} eq "-"
MC/DC0%0/2
$token eq "-" and $self->{"state"} eq "-"
$token eq "-"
$self->{"state"} eq "-"
Truth table33%1/3
A and B
A= $token eq "-"B= $self->{"state"} eq "-"
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | ($self->{state} eq '-')) { | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $self->{state} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | return $LAST_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 7 | $self->{state} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 7 | ▶ | if ($token eq '-') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | return $STATE; # wait for second '-'; | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 7 | return $EXTRA; # done with 'official' TDList format, | |||||||||||||||||||||||||||||||||||||||||
| 322 | # anything left over is extra | ||||||||||||||||||||||||||||||||||||||||||
| 323 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 1 | ); | |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | *parse = \&parse_line; # alias parse to parse_line | |||||||||||||||||||||||||||||||||||||||||
| 327 | 12 | ▶ | sub parse_line { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_line: called CC=23 SCAR=43.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 12 | my ($self, $string) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 12 | $self->{source} = $string; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 12 | map { $self->{$_} = [] } qw( last_name first_name ); # empty arrays | |||||||||||||||||||||||||||||||||||||||||
| 332 | 12 | map { $self->{$_} = '' } qw( id membership rank date club state ); # empty strings | |||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||
| 334 | 12 | ▶ | return $self->as_hash if (not $string); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 12 | my $tokenizer = String::Tokenizer->new( | |||||||||||||||||||||||||||||||||||||||||
| 337 | $string, # source string | ||||||||||||||||||||||||||||||||||||||||||
| 338 | ",\n", # delimiters | ||||||||||||||||||||||||||||||||||||||||||
| 339 | String::Tokenizer->RETAIN_WHITESPACE, | ||||||||||||||||||||||||||||||||||||||||||
| 340 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 12 | my $iter = $tokenizer->iterator; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 12 | my $state = $LAST_NAME; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | TOKEN: | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 12 | ▶ | while ($iter->hasNextToken) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | 156 | my $token = $iter->nextToken; | |||||||||||||||||||||||||||||||||||||||||
| 347 | 156 | ▶ | if ($token eq "\n") { # a carriage return? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | last TOKEN; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | ▶ | elsif ($token !~ m/\S/ or # only whitespace | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not $token =~ /\S/ or $token eq ""
MC/DC50%1/2
not $token =~ /\S/ or $token eq ""
not $token =~ /\S/
$token eq ""
Truth table66%2/3
not(A) or B
A= not $token =~ /\S/B= $token eq ""
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | $token eq '') { # empty | ||||||||||||||||||||||||||||||||||||||||||
| 352 | 67 | next TOKEN; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | elsif ($token eq '#') { # comment | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | if ($state ne $FIRST_NAME) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | $self->_parse_error( | ||||||||||||||||||||||||||||||||||||||||||
| 357 | error => "got comment, expected $name_of_state{$state}", | ||||||||||||||||||||||||||||||||||||||||||
| 358 | source => $self->{source}, | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||
| 361 | # dump the rest of the line | ||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | $iter->collectTokensUntil("\n") if ($iter->hasNextToken); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | next TOKEN; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | elsif (exists $state_functions{$state}) { | ||||||||||||||||||||||||||||||||||||||||||
| 366 | 89 | $state = $state_functions{$state}($self, $token); | |||||||||||||||||||||||||||||||||||||||||
| 367 | 86 | next TOKEN; | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | elsif ($state == $EXTRA) { | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | if ($iter->hasNextToken) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | ▶ | $token .= $iter->collectTokensUntil("\n") || ''; # slurp the rest | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$iter->collectTokensUntil("\n") || ''
MC/DC0%0/1
$iter->collectTokensUntil("\n") || ''
$iter->collectTokensUntil("\n")
Truth table0%0/2
A
A= $iter->collectTokensUntil("\n")
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | chomp $token; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | $self->{extra} = $token; | |||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | next TOKEN; | |||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||
| 377 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 378 | $self->_parse_error( | ||||||||||||||||||||||||||||||||||||||||||
| 379 | error => "Unknown state: $state", | ||||||||||||||||||||||||||||||||||||||||||
| 380 | source => $self->{source}, | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 9 | ▶ | if (length $self->{state} == 0 and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
length $self->{"state"} == 0 and length $self->{"club"} == 2 and uc $self->{"club"} eq $self->{"club"}
length $self->{"state"} == 0 and length $self->{"club"} == 2
MC/DC0%0/3
length $self->{"state"} == 0 and length $self->{"club"} == 2 and uc $self->{"club"} eq $self->{"club"}
length $self->{"state"} == 0
length $self->{"club"} == 2
uc $self->{"club"} eq $self->{"club"}
Truth table50%2/4
A and B and C
A= length $self->{"state"} == 0B= length $self->{"club"} == 2C= uc $self->{"club"} eq $self->{"club"}
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | length $self->{club} == 2 and | ||||||||||||||||||||||||||||||||||||||||||
| 386 | uc $self->{club} eq $self->{club}) { # state is in club field | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | $self->{state} = $self->{club}; | |||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | $self->{club} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 9 | ▶ | if (not $self->{id} and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not $self->{"id"} and @{$self->{"first_name"};} > 1 and $self->{"first_name"}[-1] =~ /\d/
not $self->{"id"} and @{$self->{"first_name"};} > 1
MC/DC0%0/3
not $self->{"id"} and @{$self->{"first_name"};} > 1 and $self->{"first_name"}[-1] =~ /\d/
not $self->{"id"}
@{$self->{"first_name"};} > 1
$self->{"first_name"}[-1] =~ /\d/
Truth table50%2/4
not(A) and B and C
A= not $self->{"id"}B= @{$self->{"first_name"};} > 1C= $self->{"first_name"}[-1] =~ /\d/
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | @{$self->{first_name}} > 1 and | |||||||||||||||||||||||||||||||||||||||||
| 392 | $self->{first_name}[-1] =~ m/\d/) { # digit(s) present? | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | $self->{id} = pop @{$self->{first_name}}; # probably | |||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 9 | $self->{last_name} = join(q{ }, @{$self->{last_name}}); | |||||||||||||||||||||||||||||||||||||||||
| 396 | 9 | $self->{first_name} = join(q{ }, @{$self->{first_name}}); | |||||||||||||||||||||||||||||||||||||||||
| 397 | 9 | ▶ | if ($self->rank eq '' and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->rank eq "" and is_Rank_or_Rating($self->{"id"})
MC/DC0%0/2
$self->rank eq "" and is_Rank_or_Rating($self->{"id"})
$self->rank eq ""
is_Rank_or_Rating($self->{"id"})
Truth table66%2/3
A and B
A= $self->rank eq ""B= is_Rank_or_Rating($self->{"id"})
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | is_Rank_or_Rating($self->{id})) { | ||||||||||||||||||||||||||||||||||||||||||
| 399 | # hmm, this is more likely: | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $self->rank = $self->{id}; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | $self->{id} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | 9 | ▶ | $self->{id} = normalize_ID($self->{id}) if ($self->{id}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 9 | ▶ | $self->{club} = '' if (lc $self->{club} eq 'none'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 9 | return $self->as_hash; | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | Games::Go::AGA::Parse::TDList - Parses lines from an AGA TDLISTlist | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | version 0.042 | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | use Games::Go::Parse::TDList; | ||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | my $parser = Games::Go::AGA::Parse::TDList->new; | ||||||||||||||||||||||||||||||||||||||||||
| 427 | while (my $line = <$tdlist_fh>) { | ||||||||||||||||||||||||||||||||||||||||||
| 428 | my $hash = $parser->parse($line); # ref to a hash | ||||||||||||||||||||||||||||||||||||||||||
| 429 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | A parser to break out and return fields of a line from an AGA TDListN.txt | ||||||||||||||||||||||||||||||||||||||||||
| 435 | file. The fields are usually: | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | last_name | ||||||||||||||||||||||||||||||||||||||||||
| 438 | first_name | ||||||||||||||||||||||||||||||||||||||||||
| 439 | id | ||||||||||||||||||||||||||||||||||||||||||
| 440 | membership | ||||||||||||||||||||||||||||||||||||||||||
| 441 | rank | ||||||||||||||||||||||||||||||||||||||||||
| 442 | date | ||||||||||||||||||||||||||||||||||||||||||
| 443 | club | ||||||||||||||||||||||||||||||||||||||||||
| 444 | state | ||||||||||||||||||||||||||||||||||||||||||
| 445 | extra | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | but some fields could be empty (''). | ||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||
| 449 | Note that the B<rank> field may be either rank format (3K, 4d, etc) or a | ||||||||||||||||||||||||||||||||||||||||||
| 450 | numerical rating (from -100 to +20 with a gap from -1 to +1). Rank | ||||||||||||||||||||||||||||||||||||||||||
| 451 | format implies less certainty in the accuracy of the rank. The | ||||||||||||||||||||||||||||||||||||||||||
| 452 | B<Rank_to_Rating> function in Games::Go::AGA::Parse::Utils can be used | ||||||||||||||||||||||||||||||||||||||||||
| 453 | to force the numerical format. | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | =item $parser = Games::Go::AGA::Parse::TDList->new; | ||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||
| 461 | Creates a new parser object. | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | =item $parser = $parser->filename( ['new_name']) | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | Get/set a filename (used in error messages) | ||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||
| 467 | =item $file_handle = $parser->filename( [$new_file_handle ]) | ||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||
| 469 | Get/set a file handle (used in error messages) | ||||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | =item %result_hash = $parser->parse_line('a TDListN line') | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | =item %result_hash = $parser->parse() | ||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||
| 475 | Parses a single line from the TDListN.txt file and returns a hash with the | ||||||||||||||||||||||||||||||||||||||||||
| 476 | fields as listed in B<as_hash>. Calling this function removes any field | ||||||||||||||||||||||||||||||||||||||||||
| 477 | results from previous lines. | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | =item %as_hash = $parser->as_hash() | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | Retuns the parsed line as a hash. Missing fields will be empty strings | ||||||||||||||||||||||||||||||||||||||||||
| 482 | (''). The hash keys are | ||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||
| 484 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 485 | last_name => 'last name of player', | ||||||||||||||||||||||||||||||||||||||||||
| 486 | first_name => 'first name of player', | ||||||||||||||||||||||||||||||||||||||||||
| 487 | id => 'player ID', | ||||||||||||||||||||||||||||||||||||||||||
| 488 | membership => 'AGA membership type (if any)', | ||||||||||||||||||||||||||||||||||||||||||
| 489 | rank => 'player's rank or rating', | ||||||||||||||||||||||||||||||||||||||||||
| 490 | date => 'date player's membership is valid until', | ||||||||||||||||||||||||||||||||||||||||||
| 491 | club => 'club player usually plays at', | ||||||||||||||||||||||||||||||||||||||||||
| 492 | state => 'state player lives in', | ||||||||||||||||||||||||||||||||||||||||||
| 493 | extra => 'any extra stuff', | ||||||||||||||||||||||||||||||||||||||||||
| 494 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | In scalar context, returns a reference to the hash. | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | =item @as_array = $parser->as_array() | ||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | Retuns the parsed line as an array. Missing fields will be empty strings | ||||||||||||||||||||||||||||||||||||||||||
| 501 | (''). The order is: | ||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 504 | last_name | ||||||||||||||||||||||||||||||||||||||||||
| 505 | first_name | ||||||||||||||||||||||||||||||||||||||||||
| 506 | id | ||||||||||||||||||||||||||||||||||||||||||
| 507 | membership | ||||||||||||||||||||||||||||||||||||||||||
| 508 | rank | ||||||||||||||||||||||||||||||||||||||||||
| 509 | date | ||||||||||||||||||||||||||||||||||||||||||
| 510 | club | ||||||||||||||||||||||||||||||||||||||||||
| 511 | state | ||||||||||||||||||||||||||||||||||||||||||
| 512 | extra | ||||||||||||||||||||||||||||||||||||||||||
| 513 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | In scalar context, returns a reference to the array. | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | =item $field_by_name = $parser-> < name > | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | Individual fields may be set or retrieved by name. E.g: | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | $last_name = $parser->last_name | ||||||||||||||||||||||||||||||||||||||||||
| 522 | . . . | ||||||||||||||||||||||||||||||||||||||||||
| 523 | $parser->rank('4d'); | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | =head1 OPTIONS | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | Options to the B<-E<gt>new> method are: | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | =item filename => 'file name' | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | =item handle => $file_handle | ||||||||||||||||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||||||||||||||||
| 537 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||
| 539 | These are not required to create a parser, but if supplied, error | ||||||||||||||||||||||||||||||||||||||||||
| 540 | exceptions will include more useful information. | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | Reid Augustin <reid@hellosix.com> | ||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | This software is copyright (c) 2011 by Reid Augustin. | ||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 551 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | __END__ | ||||||||||||||||||||||||||||||||||||||||||