| 1 | package Data::Validate::Sanctions::Fetcher; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use DateTime::Format::Strptime; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use Date::Utility; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 11 | ▶ | use IO::Uncompress::Unzip qw(unzip $UnzipError); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 11 | ▶ | use List::Util qw(uniq any); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 11 | ▶ | use Mojo::UserAgent; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 11 | ▶ | use Text::CSV; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 11 | ▶ | use Text::Trim qw(trim); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 11 | ▶ | use Syntax::Keyword::Try; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 11 | ▶ | use XML::Fast; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 11 | ▶ | use Locale::Country; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 11 | ▶ | use JSON qw(to_json); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 11 | ▶ | use Digest::SHA qw(sha256_hex); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 11 | ▶ | use Encode qw(encode); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 11 | ▶ | use constant MAX_REDIRECTS => 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 11 | our $VERSION = '0.21'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | =head2 config | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | Creastes a hash-ref of sanction source configuration, including their url, description and parser callback. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | It accepts the following list of named args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | =item B<-eu_token>: required if B<eu_url> is empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | The token required for accessing EU sanctions (usually added as an arg to URL). | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | =item <eu_url>: required if B<eu_token> is empty | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | EU Sanctions full url, token included. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | =item B<ofac_sdn_url>: optional | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | OFAC-SDN download url. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | =item B<ofac_consolidated_url>: optional | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | OFAC Consilidated download url. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | =item B<hmt_url>: optional | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | MHT Sanctions download url. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 13 | ▶ | sub config { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
config: called CC=16 SCAR=27.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 13 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 13 | ▶ | my $eu_token = $args{eu_token} // $ENV{EU_SANCTIONS_TOKEN}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{"eu_token"} // $ENV{"EU_SANCTIONS_TOKEN"}
MC/DC50%1/2
$args{"eu_token"} // $ENV{"EU_SANCTIONS_TOKEN"}
$args{"eu_token"}
$ENV{"EU_SANCTIONS_TOKEN"}
Truth table66%2/3
A // B
A= $args{"eu_token"}B= $ENV{"EU_SANCTIONS_TOKEN"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 13 | ▶ | my $eu_url = $args{eu_url} || $ENV{EU_SANCTIONS_URL}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{'eu_url'} || $ENV{'EU_SANCTIONS_URL'}
MC/DC50%1/2
$args{'eu_url'} || $ENV{'EU_SANCTIONS_URL'}
$args{'eu_url'}
$ENV{'EU_SANCTIONS_URL'}
Truth table66%2/3
A || B
A= $args{'eu_url'}B= $ENV{'EU_SANCTIONS_URL'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 13 | ▶ | warn 'EU Sanctions will fail without eu_token or eu_url' unless $eu_token or $eu_url; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$eu_token or $eu_url
MC/DC100%2/2
$eu_token or $eu_url
$eu_token
$eu_url
Truth table100%3/3
A or B
A= $eu_tokenB= $eu_url
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 13 | my $default_eu_base_url = 'https://webgate.ec.europa.eu/fsd/fsf/public/files/xmlFullSanctionsList_1_1/content'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 13 | ▶ | if ($eu_url && $eu_token && $eu_url !~ /[?&]token=/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%6/6
$eu_url and $eu_token and not $eu_url =~ /[?&]token=/
$eu_url and $eu_token
MC/DC100%3/3
$eu_url and $eu_token and not $eu_url =~ /[?&]token=/
$eu_url
$eu_token
not $eu_url =~ /[?&]token=/
Truth table100%4/4
A and B and not(C)
A= $eu_urlB= $eu_tokenC= not $eu_url =~ /[?&]token=/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | ▶ | my $separator = $eu_url =~ /\?/ ? '&' : '?'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | $eu_url = "${eu_url}${separator}token=${eu_token}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ▶ | } elsif (!$eu_url && $eu_token) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
not $eu_url and $eu_token
MC/DC100%2/2
not $eu_url and $eu_token
not $eu_url
$eu_token
Truth table100%3/3
not(A) and B
A= not $eu_urlB= $eu_token
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | $eu_url = "${default_eu_base_url}?token=${eu_token}"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 'OFAC-SDN' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | description => 'TREASURY.GOV: Specially Designated Nationals List with a.k.a included', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | url => $args{ofac_sdn_url} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | || 'https://www.treasury.gov/ofac/downloads/sdn_xml.zip', #let's be polite and use zippped version of this 7mb+ file | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | parser => \&_ofac_xml_zip, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 'OFAC-Consolidated' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | description => 'TREASURY.GOV: Consolidated Sanctions List Data Files', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | url => $args{ofac_consolidated_url} || 'https://www.treasury.gov/ofac/downloads/consolidated/consolidated.xml', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | parser => \&_ofac_xml, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 'HMT-Sanctions' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | description => 'GOV.UK: Financial sanctions: consolidated list of targets', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | url => $args{hmt_url} || 'https://ofsistorage.blob.core.windows.net/publishlive/ConList.csv', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | parser => \&_hmt_csv, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 'EU-Sanctions' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | description => 'EUROPA.EU: Consolidated list of persons, groups and entities subject to EU financial sanctions', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | url => $eu_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | parser => \&_eu_xml, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 'UNSC-Sanctions' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | description => 'UN: United Nations Security Council Consolidated List', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | url => $args{unsc_url} || 'https://scsanctions.un.org/resources/xml/en/consolidated.xml', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | parser => \&_unsc_xml, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 'MOHA-Sanctions' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | description => 'MOHA: Sanction list made by the ministry of home affairs Malaysia', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 13 | ▶ | url => $args{moha_url} || 'https://www.moha.gov.my/utama/images/Terkini/SENARAI_KDN_2026_BI_1.xml', | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition70%7/10
$args{'ofac_sdn_url'} || 'https://www.treasury.gov/ofac/downloads/sdn_xml.zip'
$args{'ofac_consolidated_url'} || 'https://www.treasury.gov/ofac/downloads/consolidated/consolidated.xml'
$args{'hmt_url'} || 'https://ofsistorage.blob.core.windows.net/publishlive/ConList.csv'
$args{'unsc_url'} || 'https://scsanctions.un.org/resources/xml/en/consolidated.xml'
$args{'moha_url'} || 'https://www.moha.gov.my/utama/images/Terkini/SENARAI_KDN_2026_BI_1.xml'
MC/DC0%0/1
$args{'ofac_sdn_url'} || 'https://www.treasury.gov/ofac/downloads/sdn_xml.zip'
$args{'ofac_sdn_url'}
MC/DC0%0/1
$args{'ofac_consolidated_url'} || 'https://www.treasury.gov/ofac/downloads/consolidated/consolidated.xml'
$args{'ofac_consolidated_url'}
MC/DC0%0/1
$args{'hmt_url'} || 'https://ofsistorage.blob.core.windows.net/publishlive/ConList.csv'
$args{'hmt_url'}
MC/DC100%1/1
$args{'unsc_url'} || 'https://scsanctions.un.org/resources/xml/en/consolidated.xml'
$args{'unsc_url'}
MC/DC100%1/1
$args{'moha_url'} || 'https://www.moha.gov.my/utama/images/Terkini/SENARAI_KDN_2026_BI_1.xml'
$args{'moha_url'}
Truth table50%1/2
A
A= $args{'ofac_sdn_url'}
Truth table50%1/2
A
A= $args{'ofac_consolidated_url'}
Truth table50%1/2
A
A= $args{'hmt_url'}
Truth table100%2/2
A
A= $args{'unsc_url'}
Truth table100%2/2
A
A= $args{'moha_url'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | parser => \&_moha_xml, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # Parsers - returns timestamp of last update and arrayref of names | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1020 | ▶ | sub _process_name { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 1020 | my $r = join ' ', @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1020 | $r =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 1020 | return $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 12 | ▶ | sub _ofac_xml_zip { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ofac_xml_zip: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 12 | my $raw_data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 12 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 12 | ▶ | unzip \$raw_data => \$output or die "unzip failed: $UnzipError\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 12 | return _ofac_xml($output); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1155 | ▶ | sub _date_to_epoch { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_date_to_epoch: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 1155 | my $date = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 1155 | ▶ | return unless defined $date && $date ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $date and $date ne ""
MC/DC100%2/2
defined $date and $date ne ""
defined $date
$date ne ""
Truth table100%3/3
A and B
A= defined $dateB= $date ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | # Handle ISO 8601 format (YYYY-MM-DDTHH:MM:SS+TZ or variations) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 1153 | ▶ | if ($date =~ m/^(\d{4})-(\d{2})-(\d{2})(?:T[\d:+-]+)?/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | # Already in YYYY-MM-DD format, just remove time/timezone part | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 107 | $date = "$1-$2-$3"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # Handle DD/MM/YYYY or DD-MM-YYYY format | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | elsif ($date =~ m/^(\d{1,2})[\/\-](\d{1,2})[\/\-](\d{4})$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 107 | $date = "$3-$2-$1"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 1153 | my $result = eval { Date::Utility->new($date)->epoch; }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1153 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | =head2 get_country_code | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | If the arg is a country code, it's returned in lower case; otherwise the arg is converted to country code. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3369 | ▶ | sub get_country_code { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_country_code: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 3369 | my $value = trim shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 3369 | ▶ | return lc(code2country($value) ? $value : country2code($value) // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
country2code($value) // ""
MC/DC100%1/1
country2code($value) // ""
country2code($value)
Truth table100%2/2
A
A= country2code($value)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | =head2 _process_sanction_entry | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | Processes an entry retrieved from sanction resources and saves it into the specified key-value dataset. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | An entry may have multilpe names (aliases), each of which will be taken as a key in the dataset with the same values/info. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | It takes following list of args: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | =item - dataset: A hash ref of form [ name => info ] in which the entry will be saved | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | =item - data: a hash of entry data that may contain: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | =item * name: an array of names/aliases | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | =item * date_of_birth: an array of dates of birth | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | Dates of birth are not of standardized format in some data sources; so they are processed in three steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1- as a first step it will be tried to converetd them into epoch, saved as B<dob_epoch>; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 2- otherwise to extract year (or an array of years) of birth, saved as B<dob_year>; and | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 3- finally, to saved as raw text in B<dob_text>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | =item * place_of_birth: an array of country names or codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | =item * residence: an array of country names or codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | =item * nationality: an array of country names or codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | =item * citizen: an array of country names or codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | =item * postal_code: an array of postal/zip codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | =item * national_id: an array of national ID numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | =item * passport_no: an array of passort numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 1406 | ▶ | sub _process_sanction_entry { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_process_sanction_entry: called CC=17 SCAR=28.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 1406 | my ($dataset, %data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1406 | my @dob_list = $data{date_of_birth}->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1406 | my (@dob_epoch, @dob_year, @dob_text); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1406 | for my $dob (@dob_list) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1561 | $dob = trim($dob); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1561 | ▶ | next unless $dob; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 1561 | $dob =~ s/[ \/]/-/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | #dobs with month = day = 0 are converted to year. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1561 | ▶ | if ($dob =~ m/^(\d{1,2})-(\d{1,2})-(\d{4})$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 276 | ▶ | $dob = $3 if $1 == 0 or $2 == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$1 == 0 or $2 == 0
MC/DC100%2/2
$1 == 0 or $2 == 0
$1 == 0
$2 == 0
Truth table100%3/3
A or B
A= $1 == 0B= $2 == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } elsif ($dob =~ m/^(\d{4})-(\d0{1,2})-(\d{1,2})$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $dob = $1 if $2 == 0 or $3 == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$2 == 0 or $3 == 0
MC/DC0%0/2
$2 == 0 or $3 == 0
$2 == 0
$3 == 0
Truth table0%0/3
A or B
A= $2 == 0B= $3 == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1561 | ▶ | $dob = $1 if $dob =~ m/^[A-Z][a-z]{2}-(\d{4})$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1561 | ▶ | if ($dob =~ m/^\d{4}$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 371 | push @dob_year, $dob; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } elsif ($dob =~ m/(\d{4}).*to.*(\d{4})$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 144 | push @dob_year, ($1 .. $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 1046 | my $epoch = _date_to_epoch($dob); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1046 | ▶ | (defined $epoch) ? push(@dob_epoch, $epoch) : push(@dob_text, $dob); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1406 | delete $data{date_of_birth}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1406 | $data{dob_epoch} = \@dob_epoch; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1406 | $data{dob_year} = \@dob_year; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1406 | $data{dob_text} = \@dob_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | # convert all country names to iso codes | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1406 | for my $field (qw/place_of_birth residence nationality citizen/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5624 | $data{$field} = [map { get_country_code($_) } $data{$field}->@*]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5624 | $data{$field} = [grep { $_ } $data{$field}->@*]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | # remove commas | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 1406 | $data{names} = [map { trim($_) =~ s/,//gr } $data{names}->@*]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | # make values unique | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 1406 | %data = map { $_ => [uniq $data{$_}->@*] } keys %data; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # remove empty values | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 1406 | for (keys %data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # dob = 0 is acceptable | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 14337 | ▶ | next if $_ eq 'dob_epoch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 12931 | $data{$_} = [grep { $_ } $data{$_}->@*]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # remove fields with empty list | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1406 | %data = %data{grep { $data{$_}->@* } keys %data}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1406 | ▶ | push $dataset->@*, \%data if $data{names}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 1406 | return $dataset; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 24 | ▶ | sub _ofac_xml { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ofac_xml: called CC=15 SCAR=27.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 24 | my $raw_data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 24 | my $ref = xml2hash($raw_data, array => ['aka'])->{sdnList}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | my $publish_epoch = | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 24 | ▶ | $ref->{publshInformation}{Publish_Date} =~ m/(\d{1,2})\/(\d{1,2})\/(\d{4})/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | ? _date_to_epoch("$3-$1-$2") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | : undef; # publshInformation is a typo in ofac xml tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 24 | ▶ | die "Corrupt data. Release date is invalid\n" unless defined $publish_epoch; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 864 | ▶ | my $parse_list_node = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 864 | my ($entry, $parent, $child, $attribute) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 864 | ▶ | my $node = $entry->{$parent}->{$child} // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$entry->{$parent}{$child} // []
MC/DC100%1/1
$entry->{$parent}{$child} // []
$entry->{$parent}{$child}
Truth table100%2/2
A
A= $entry->{$parent}{$child}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 864 | ▶ | $node = [$node] if (ref $node eq 'HASH'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 864 | ▶ | return map { $_->{$attribute} // () } @$node; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_->{$attribute} // ()
MC/DC0%0/2
$_->{$attribute} // ()
$_->{$attribute}
()
Truth table66%2/3
A // B
A= $_->{$attribute}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 24 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 24 | my $dataset = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 24 | foreach my $entry (@{$ref->{sdnEntry}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 192 | ▶ | next unless $entry->{sdnType} eq 'Individual'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 144 | my @names; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 144 | ▶ | for ($entry, @{$entry->{akaList}{aka} // []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$entry->{"akaList"}{"aka"} // []
MC/DC100%1/1
$entry->{"akaList"}{"aka"} // []
$entry->{"akaList"}{"aka"}
Truth table100%2/2
A
A= $entry->{"akaList"}{"aka"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 792 | ▶ | my $category = $_->{category} // 'strong'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_->{"category"} // "strong"
MC/DC100%1/1
$_->{"category"} // "strong"
$_->{"category"}
Truth table100%2/2
A
A= $_->{"category"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 792 | ▶ | push @names, _process_name($_->{firstName} // '', $_->{lastName} // '') if $category eq 'strong'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%2/4
$_->{"firstName"} // ""
$_->{"lastName"} // ""
MC/DC0%0/1
$_->{"firstName"} // ""
$_->{"firstName"}
MC/DC0%0/1
$_->{"lastName"} // ""
$_->{"lastName"}
Truth table50%1/2
A
A= $_->{"firstName"}
Truth table50%1/2
A
A= $_->{"lastName"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | # my @dob_list; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # my $dobs = $entry->{dateOfBirthList}{dateOfBirthItem}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # # In one of the xml files, some of the clients have more than one date of birth | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | # # Hence, $dob can be either an array or a hashref | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | # foreach my $dob (map { $_->{dateOfBirth} || () } (ref($dobs) eq 'ARRAY' ? @$dobs : $dobs)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # push @dob_list, $dob; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | # } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 144 | my @dob_list = $parse_list_node->($entry, 'dateOfBirthList', 'dateOfBirthItem', 'dateOfBirth'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 144 | my @citizen = $parse_list_node->($entry, 'citizenshipList', 'citizenship', 'country'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 144 | my @residence = $parse_list_node->($entry, 'addressList', 'address', 'country'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 144 | my @postal_code = $parse_list_node->($entry, 'addressList', 'address', 'postalCode'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 144 | my @nationality = $parse_list_node->($entry, 'naationalityList', 'nationality', 'country'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 144 | my @place_of_birth = $parse_list_node->($entry, 'placeOfBirthList', 'placeOfBirthItem', 'placeOfBirth'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 144 | @place_of_birth = map { my @parts = split ',', $_; $parts[-1] } @place_of_birth; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 144 | ▶ | my $id_list = $entry->{idList}->{id} // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$entry->{"idList"}{"id"} // []
MC/DC100%1/1
$entry->{"idList"}{"id"} // []
$entry->{"idList"}{"id"}
Truth table100%2/2
A
A= $entry->{"idList"}{"id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 144 | ▶ | $id_list = [$id_list] if ref $id_list eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 144 | ▶ | my @passport_no = map { $_->{idType} eq 'Passport' ? $_->{idNumber} : () } @$id_list; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 144 | ▶ | my @national_id = map { $_->{idType} =~ 'National ID' ? $_->{idNumber} : () } @$id_list; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 144 | _process_sanction_entry( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | names => \@names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | date_of_birth => \@dob_list, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | place_of_birth => \@place_of_birth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | residence => \@residence, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | nationality => \@nationality, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | citizen => \@citizen, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | postal_code => \@postal_code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | national_id => \@national_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | passport_no => \@passport_no, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 24 | updated => $publish_epoch, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | content => $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 12 | ▶ | sub _hmt_csv { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hmt_csv: called CC=14 SCAR=27.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 12 | my $raw_data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 12 | my $dataset = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 12 | ▶ | my $csv = Text::CSV->new({binary => 1}) or die "Cannot use CSV: " . Text::CSV->error_diag() . "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 12 | my @lines = split("\n", $raw_data); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 12 | my $parsed = $csv->parse(trim(shift @lines)); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 12 | ▶ | my @info = $parsed ? $csv->fields() : (); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 12 | ▶ | die "Currupt data. Release date was not found\n" unless @info && _date_to_epoch($info[1]); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@info and _date_to_epoch($info[1])
MC/DC0%0/2
@info and _date_to_epoch($info[1])
@info
_date_to_epoch($info[1])
Truth table33%1/3
A and B
A= @infoB= _date_to_epoch($info[1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 12 | my $publish_epoch = _date_to_epoch($info[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 12 | ▶ | die "Currupt data. Release date is invalid\n" unless defined $publish_epoch; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 12 | $parsed = $csv->parse(trim(shift @lines)); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 12 | my @row = $csv->fields(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 12 | my %column = map { trim($row[$_]) => $_ } (0 .. @row - 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 12 | foreach my $line (@lines) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 276 | $line = trim($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 276 | $parsed = $csv->parse($line); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 276 | ▶ | next unless $parsed; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 276 | my @row = $csv->fields(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 276 | @row = map { trim($_ =~ s/\([^(]*\)$//r) } @row; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 276 | ▶ | ($row[$column{'Group Type'}] eq "Individual") or next; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 276 | my $name = _process_name @row[0 .. 5]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 276 | ▶ | next if $name =~ /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 276 | my $date_of_birth = $row[$column{'DOB'}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 276 | my $place_of_birth = $row[$column{'Country of Birth'}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | # nationality is saved as an adjective (Iranian, American, etc); let's ignore it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 276 | my $nationality = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 276 | my $residence = $row[$column{'Country'}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 276 | my $postal_code = $row[$column{'Post/Zip Code'}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 276 | my $national_id = $row[$column{'National Identification Number'}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | # Fields to be added in the new file format (https://redmine.deriv.cloud/issues/51922) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | # We can read these fields normally after the data is released in the new format | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 276 | my ($passport_no, $non_latin_alias); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 276 | ▶ | $passport_no = $row[$column{'Passport Number'}] if defined $column{'Passport Number'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 276 | ▶ | $non_latin_alias = $row[$column{'Name Non-Latin Script'}] if defined $column{'Name Non-Latin Script'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 276 | ▶ | _process_sanction_entry( | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | names => [$name, $non_latin_alias ? $non_latin_alias : ()], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | date_of_birth => [$date_of_birth], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | place_of_birth => [$place_of_birth], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | residence => [$residence], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | nationality => [$nationality], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | postal_code => [$postal_code], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | national_id => [$national_id], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | $passport_no ? (passport_no => [$passport_no]) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 12 | updated => $publish_epoch, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | content => $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 7 | ▶ | sub _eu_xml { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_eu_xml: called CC=29 SCAR=39.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 7 | my $raw_data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 7 | my $ref = xml2hash($raw_data, array => ['nameAlias', 'birthdate'])->{export}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 7 | my $dataset = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 7 | foreach my $entry (@{$ref->{sanctionEntity}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 49 | ▶ | next unless $entry->{subjectType}->{'-code'} eq 'person'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 49 | for (qw/birthdate citizenship address identification/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 196 | ▶ | $entry->{$_} //= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$entry->{$_} //= []
MC/DC100%1/1
$entry->{$_} //= []
$entry->{$_}
Truth table100%2/2
A
A= $entry->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 196 | ▶ | $entry->{$_} = [$entry->{$_}] if ref $entry->{$_} eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 49 | my @names; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 49 | ▶ | for (@{$entry->{nameAlias} // []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entry->{"nameAlias"} // []
MC/DC0%0/1
$entry->{"nameAlias"} // []
$entry->{"nameAlias"}
Truth table50%1/2
A
A= $entry->{"nameAlias"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 105 | my $name = $_->{'-wholeName'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 105 | ▶ | $name = join ' ', ($_->{'-firstName'} // '', $_->{'-lastName'} // '') unless $name; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$_->{"-firstName"} // ""
$_->{"-lastName"} // ""
MC/DC0%0/1
$_->{"-firstName"} // ""
$_->{"-firstName"}
MC/DC0%0/1
$_->{"-lastName"} // ""
$_->{"-lastName"}
Truth table0%0/2
A
A= $_->{"-firstName"}
Truth table0%0/2
A
A= $_->{"-lastName"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 105 | ▶ | push @names, $name if $name ne ' '; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 49 | my @dob_list; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 49 | foreach my $dob ($entry->{birthdate}->@*) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 63 | ▶ | push @dob_list, $dob->{'-birthdate'} if $dob->{'-birthdate'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 63 | ▶ | push @dob_list, $dob->{'-year'} if not $dob->{'-birthdate'} and $dob->{'-year'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $dob->{"-birthdate"} and $dob->{"-year"}
MC/DC50%1/2
not $dob->{"-birthdate"} and $dob->{"-year"}
not $dob->{"-birthdate"}
$dob->{"-year"}
Truth table66%2/3
not(A) and B
A= not $dob->{"-birthdate"}B= $dob->{"-year"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 49 | ▶ | my @place_of_birth = map { $_->{'-countryIso2Code'} || () } $entry->{birthdate}->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_->{'-countryIso2Code'} || ()
MC/DC0%0/2
$_->{'-countryIso2Code'} || ()
$_->{'-countryIso2Code'}
()
Truth table33%1/3
A || B
A= $_->{'-countryIso2Code'}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 49 | ▶ | my @citizen = map { $_->{'-countryIso2Code'} || () } $entry->{citizenship}->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_->{'-countryIso2Code'} || ()
MC/DC0%0/2
$_->{'-countryIso2Code'} || ()
$_->{'-countryIso2Code'}
()
Truth table33%1/3
A || B
A= $_->{'-countryIso2Code'}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 49 | ▶ | my @residence = map { $_->{'-countryIso2Code'} || () } $entry->{address}->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_->{'-countryIso2Code'} || ()
MC/DC0%0/2
$_->{'-countryIso2Code'} || ()
$_->{'-countryIso2Code'}
()
Truth table33%1/3
A || B
A= $_->{'-countryIso2Code'}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 49 | ▶ | my @postal_code = map { $_->{'-zipCode'} || $_->{'-poBox'} || () } $entry->{address}->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%2/6
$_->{'-zipCode'} || $_->{'-poBox'} || ()
$_->{"-zipCode"} or $_->{"-poBox"}
MC/DC0%0/3
$_->{'-zipCode'} || $_->{'-poBox'} || ()
$_->{"-zipCode"}
$_->{"-poBox"}
()
Truth table25%1/4
A or B || C
A= $_->{"-zipCode"}B= $_->{"-poBox"}C= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 49 | ▶ | my @nationality = map { $_->{'-countryIso2Code'} || () } $entry->{identification}->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$_->{'-countryIso2Code'} || ()
MC/DC0%0/2
$_->{'-countryIso2Code'} || ()
$_->{'-countryIso2Code'}
()
Truth table33%1/3
A || B
A= $_->{'-countryIso2Code'}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 49 | ▶ | my @national_id = map { $_->{'-identificationTypeCode'} eq 'id' ? $_->{'-number'} || () : () } $entry->{identification}->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_->{"-number"} or ()
MC/DC0%0/2
$_->{"-number"} or ()
$_->{"-number"}
()
Truth table33%1/3
A or B
A= $_->{"-number"}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 49 | ▶ | my @passport_no = map { $_->{'-identificationTypeCode'} eq 'passport' ? $_->{'-number'} || () : () } $entry->{identification}->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_->{"-number"} or ()
MC/DC0%0/2
$_->{"-number"} or ()
$_->{"-number"}
()
Truth table33%1/3
A or B
A= $_->{"-number"}B= ()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 49 | _process_sanction_entry( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | names => \@names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | date_of_birth => \@dob_list, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | place_of_birth => \@place_of_birth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | residence => \@residence, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | nationality => \@nationality, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | citizen => \@citizen, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | postal_code => \@postal_code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | national_id => \@national_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | passport_no => \@passport_no, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 7 | ▶ | my @date_parts = split('T', $ref->{'-generationDate'} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ref->{"-generationDate"} // ""
MC/DC0%0/1
$ref->{"-generationDate"} // ""
$ref->{"-generationDate"}
Truth table50%1/2
A
A= $ref->{"-generationDate"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 7 | ▶ | my $publish_epoch = _date_to_epoch($date_parts[0] // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$date_parts[0] // ""
MC/DC0%0/1
$date_parts[0] // ""
$date_parts[0]
Truth table50%1/2
A
A= $date_parts[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 7 | ▶ | die "Corrupt data. Release date is invalid\n" unless $publish_epoch; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 7 | updated => $publish_epoch, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | content => $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 12 | ▶ | sub _unsc_xml { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unsc_xml: called CC=34 SCAR=37.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 12 | my ($xml_content) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # Preprocess the XML content to escape unescaped ampersands | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 12 | $xml_content =~ s/&(?!(?:amp|lt|gt|quot|apos);)/&/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | my $data = xml2hash($xml_content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | array => | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | ['INDIVIDUAL', 'INDIVIDUAL_ALIAS', 'INDIVIDUAL_ADDRESS', 'INDIVIDUAL_DATE_OF_BIRTH', 'INDIVIDUAL_PLACE_OF_BIRTH', 'INDIVIDUAL_DOCUMENT']) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 12 | ->{CONSOLIDATED_LIST}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | # Extract the dateGenerated attribute from the first line of the XML content | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | 12 | my ($date_generated) = $data->{'-dateGenerated'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 12 | ▶ | die "Corrupt data. Release date is missing\n" unless $date_generated; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # Convert the dateGenerated to epoch milliseconds | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 12 | ▶ | my $publish_epoch = _date_to_epoch($date_generated // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$date_generated // ""
MC/DC0%0/1
$date_generated // ""
$date_generated
Truth table50%1/2
A
A= $date_generated
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 12 | my $dataset = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 12 | for my $individual (@{$data->{'INDIVIDUALS'}->{'INDIVIDUAL'}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 84 | my %entry; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 84 | $entry{first_name} = $individual->{'FIRST_NAME'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 84 | $entry{second_name} = $individual->{'SECOND_NAME'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 84 | ▶ | $entry{third_name} = $individual->{'THIRD_NAME'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$individual->{"THIRD_NAME"} // ""
MC/DC100%1/1
$individual->{"THIRD_NAME"} // ""
$individual->{"THIRD_NAME"}
Truth table100%2/2
A
A= $individual->{"THIRD_NAME"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 84 | ▶ | $entry{fourth_name} = $individual->{'FOURTH_NAME'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$individual->{"FOURTH_NAME"} // ""
MC/DC100%1/1
$individual->{"FOURTH_NAME"} // ""
$individual->{"FOURTH_NAME"}
Truth table100%2/2
A
A= $individual->{"FOURTH_NAME"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 84 | ▶ | $entry{name_original_script} = $individual->{'NAME_ORIGINAL_SCRIPT'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$individual->{"NAME_ORIGINAL_SCRIPT"} // ""
MC/DC0%0/1
$individual->{"NAME_ORIGINAL_SCRIPT"} // ""
$individual->{"NAME_ORIGINAL_SCRIPT"}
Truth table50%1/2
A
A= $individual->{"NAME_ORIGINAL_SCRIPT"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | my @names = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | $entry{first_name} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | $entry{second_name} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | $entry{third_name} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | $entry{fourth_name} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 84 | ▶ | $entry{name_original_script} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition60%6/10
$entry{"first_name"} // ""
$entry{"second_name"} // ""
$entry{"third_name"} // ""
$entry{"fourth_name"} // ""
$entry{"name_original_script"} // ""
MC/DC0%0/1
$entry{"first_name"} // ""
$entry{"first_name"}
MC/DC100%1/1
$entry{"second_name"} // ""
$entry{"second_name"}
MC/DC0%0/1
$entry{"third_name"} // ""
$entry{"third_name"}
MC/DC0%0/1
$entry{"fourth_name"} // ""
$entry{"fourth_name"}
MC/DC0%0/1
$entry{"name_original_script"} // ""
$entry{"name_original_script"}
Truth table50%1/2
A
A= $entry{"first_name"}
Truth table100%2/2
A
A= $entry{"second_name"}
Truth table50%1/2
A
A= $entry{"third_name"}
Truth table50%1/2
A
A= $entry{"fourth_name"}
Truth table50%1/2
A
A= $entry{"name_original_script"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 84 | foreach my $alias (@{$individual->{INDIVIDUAL_ALIAS}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | ▶ | if (ref($alias->{'ALIAS_NAME'}) ne 'HASH' || %{$alias->{'ALIAS_NAME'}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $alias->{"ALIAS_NAME"} ne "HASH" or %{$alias->{"ALIAS_NAME"};}
MC/DC0%0/2
ref $alias->{"ALIAS_NAME"} ne "HASH" or %{$alias->{"ALIAS_NAME"};}
ref $alias->{"ALIAS_NAME"} ne "HASH"
%{$alias->{"ALIAS_NAME"};}
Truth table33%1/3
A or B
A= ref $alias->{"ALIAS_NAME"} ne "HASH"B= %{$alias->{"ALIAS_NAME"};}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 408 | ▶ | push @names, $alias->{'ALIAS_NAME'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$alias->{"ALIAS_NAME"} // ""
MC/DC0%0/1
$alias->{"ALIAS_NAME"} // ""
$alias->{"ALIAS_NAME"}
Truth table50%1/2
A
A= $alias->{"ALIAS_NAME"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 84 | my @dob_list; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 84 | ▶ | if ($individual->{'INDIVIDUAL_DATE_OF_BIRTH'}[0]{'TYPE_OF_DATE'} && $individual->{'INDIVIDUAL_DATE_OF_BIRTH'}[0]{'TYPE_OF_DATE'} eq 'BETWEEN') | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TYPE_OF_DATE"} and $individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TYPE_OF_DATE"} eq "BETWEEN"
MC/DC50%1/2
$individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TYPE_OF_DATE"} and $individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TYPE_OF_DATE"} eq "BETWEEN"
$individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TYPE_OF_DATE"}
$individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TYPE_OF_DATE"} eq "BETWEEN"
Truth table66%2/3
A and B
A= $individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TYPE_OF_DATE"}B= $individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TYPE_OF_DATE"} eq "BETWEEN"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 12 | ▶ | push @dob_list, $individual->{'INDIVIDUAL_DATE_OF_BIRTH'}[0]{'FROM_YEAR'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"FROM_YEAR"} // ""
MC/DC0%0/1
$individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"FROM_YEAR"} // ""
$individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"FROM_YEAR"}
Truth table50%1/2
A
A= $individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"FROM_YEAR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 12 | ▶ | push @dob_list, $individual->{'INDIVIDUAL_DATE_OF_BIRTH'}[0]{'TO_YEAR'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TO_YEAR"} // ""
MC/DC0%0/1
$individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TO_YEAR"} // ""
$individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TO_YEAR"}
Truth table50%1/2
A
A= $individual->{"INDIVIDUAL_DATE_OF_BIRTH"}[0]{"TO_YEAR"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 72 | ▶ | if ($individual->{'INDIVIDUAL_DATE_OF_BIRTH'}[0]{'DATE'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 12 | @dob_list = $individual->{'INDIVIDUAL_DATE_OF_BIRTH'}[0]{'DATE'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | } elsif ($individual->{'INDIVIDUAL_DATE_OF_BIRTH'}[0]{'YEAR'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 60 | @dob_list = $individual->{'INDIVIDUAL_DATE_OF_BIRTH'}[0]{'YEAR'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | my @place_of_birth = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | $individual->{'INDIVIDUAL_PLACE_OF_BIRTH'}[0]{'CITY'} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | $individual->{'INDIVIDUAL_PLACE_OF_BIRTH'}[0]{'STATE_PROVINCE'} // '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 84 | ▶ | $individual->{'INDIVIDUAL_PLACE_OF_BIRTH'}[0]{'COUNTRY'} // '' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"CITY"} // ""
$individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"STATE_PROVINCE"} // ""
$individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"COUNTRY"} // ""
MC/DC100%1/1
$individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"CITY"} // ""
$individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"CITY"}
MC/DC100%1/1
$individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"STATE_PROVINCE"} // ""
$individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"STATE_PROVINCE"}
MC/DC0%0/1
$individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"COUNTRY"} // ""
$individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"COUNTRY"}
Truth table100%2/2
A
A= $individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"CITY"}
Truth table100%2/2
A
A= $individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"STATE_PROVINCE"}
Truth table50%1/2
A
A= $individual->{"INDIVIDUAL_PLACE_OF_BIRTH"}[0]{"COUNTRY"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 84 | ▶ | my @residence = (map { $_->{'COUNTRY'} // '' } @{$individual->{'INDIVIDUAL_ADDRESS'}}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$_->{"COUNTRY"} // ""
MC/DC0%0/1
$_->{"COUNTRY"} // ""
$_->{"COUNTRY"}
Truth table50%1/2
A
A= $_->{"COUNTRY"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 84 | ▶ | my @postal_code = (map { $_->{'ZIP_CODE'} // '' } @{$individual->{'INDIVIDUAL_ADDRESS'}}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_->{"ZIP_CODE"} // ""
MC/DC100%1/1
$_->{"ZIP_CODE"} // ""
$_->{"ZIP_CODE"}
Truth table100%2/2
A
A= $_->{"ZIP_CODE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 84 | ▶ | my @nationality = ($individual->{'NATIONALITY'}->{'VALUE'} // ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$individual->{"NATIONALITY"}{"VALUE"} // ""
MC/DC0%0/1
$individual->{"NATIONALITY"}{"VALUE"} // ""
$individual->{"NATIONALITY"}{"VALUE"}
Truth table50%1/2
A
A= $individual->{"NATIONALITY"}{"VALUE"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 84 | my @national_id = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 84 | my @passport_no = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # Extract passport and national identification numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 84 | foreach my $document (@{$individual->{INDIVIDUAL_DOCUMENT}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 120 | ▶ | if ($document ne "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 48 | ▶ | if ($document->{'TYPE_OF_DOCUMENT'} eq 'Passport') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 36 | ▶ | push @passport_no, $document->{'NUMBER'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$document->{"NUMBER"} // ""
MC/DC0%0/1
$document->{"NUMBER"} // ""
$document->{"NUMBER"}
Truth table50%1/2
A
A= $document->{"NUMBER"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } elsif ($document->{'TYPE_OF_DOCUMENT'} eq 'National Identification Number') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 12 | ▶ | push @national_id, $document->{'NUMBER'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$document->{"NUMBER"} // ""
MC/DC0%0/1
$document->{"NUMBER"} // ""
$document->{"NUMBER"}
Truth table50%1/2
A
A= $document->{"NUMBER"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | _process_sanction_entry( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 84 | $dataset, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | names => \@names, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | date_of_birth => \@dob_list, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | place_of_birth => \@place_of_birth, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | residence => \@residence, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | nationality => \@nationality, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | citizen => \@nationality, # no seprate field for citizenship in the XML | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | postal_code => \@postal_code, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | national_id => \@national_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | passport_no => \@passport_no, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 12 | updated => $publish_epoch, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | content => $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | =head2 _moha_xml | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | Parses the XML data from MOHA (Ministry of Home Affairs Malaysia) and returns a hash-ref of the parsed data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 12 | ▶ | sub _moha_xml { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_moha_xml: called CC=4 SCAR=14.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 12 | my $raw_data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | # Parse the XML data using XML::Fast | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 12 | my $data = eval { xml2hash($raw_data) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 12 | ▶ | if ($@ || !$data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or not $data
MC/DC0%0/2
$@ or not $data
$@
not $data
Truth table33%1/3
A or not(B)
A= $@B= not $data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | warn "Error parsing XML: $@\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | # Detect new xmlResponse format vs legacy TaggedPDF-doc format | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 12 | ▶ | if (exists $data->{'xmlResponse'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | $data = xml2hash($raw_data, array => ['entry', 'field', 'section']); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 1 | return _moha_xml_new($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 11 | return _moha_xml_legacy($raw_data, $data); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | =head2 _moha_xml_new | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | Parses the new xmlResponse format from MOHA sanctions list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 1 | ▶ | sub _moha_xml_new { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_moha_xml_new: called CC=34 SCAR=39.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 1 | my $dataset = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 1 | ▶ | my $xml = $data->{'xmlResponse'} or die "Invalid MOHA xmlResponse format\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 1 | my $publish_epoch = time(); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 1 | ▶ | my $sections = $xml->{'section'} // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$xml->{"section"} // []
MC/DC0%0/1
$xml->{"section"} // []
$xml->{"section"}
Truth table50%1/2
A
A= $xml->{"section"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | for my $section (@$sections) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 1 | ▶ | my $entries = $section->{'entry'} // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$section->{"entry"} // []
MC/DC0%0/1
$section->{"entry"} // []
$section->{"entry"}
Truth table50%1/2
A
A= $section->{"entry"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 1 | for my $entry (@$entries) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 6 | ▶ | my $fields = $entry->{'field'} // []; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entry->{"field"} // []
MC/DC0%0/1
$entry->{"field"} // []
$entry->{"field"}
Truth table50%1/2
A
A= $entry->{"field"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 6 | my %f; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 6 | for my $field (@$fields) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 66 | ▶ | my $name = $field->{'-name'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$field->{"-name"} // ""
MC/DC0%0/1
$field->{"-name"} // ""
$field->{"-name"}
Truth table50%1/2
A
A= $field->{"-name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 66 | ▶ | my $value = $field->{'#text'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$field->{"#text"} // ""
MC/DC0%0/1
$field->{"#text"} // ""
$field->{"#text"}
Truth table50%1/2
A
A= $field->{"#text"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | # Normalize whitespace in field names (real XML has newlines between column number and label) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 66 | $name =~ s/\s+/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 66 | $f{$name} = trim($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 6 | my $is_individual = exists $f{'(6) Date of Birth'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 6 | ▶ | my $name = $f{'(3) Name'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$f{"(3) Name"} // ""
MC/DC0%0/1
$f{"(3) Name"} // ""
$f{"(3) Name"}
Truth table50%1/2
A
A= $f{"(3) Name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 6 | ▶ | next unless $name && $name ne '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$name and $name ne "-"
MC/DC0%0/2
$name and $name ne "-"
$name
$name ne "-"
Truth table33%1/3
A and B
A= $nameB= $name ne "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 6 | ▶ | if ($is_individual) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 4 | ▶ | my $dob_raw = $f{'(6) Date of Birth'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$f{"(6) Date of Birth"} // ""
MC/DC0%0/1
$f{"(6) Date of Birth"} // ""
$f{"(6) Date of Birth"}
Truth table50%1/2
A
A= $f{"(6) Date of Birth"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 4 | ▶ | my $pob = $f{'(7) Place of Birth'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$f{"(7) Place of Birth"} // ""
MC/DC0%0/1
$f{"(7) Place of Birth"} // ""
$f{"(7) Place of Birth"}
Truth table50%1/2
A
A= $f{"(7) Place of Birth"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 4 | ▶ | my $other_names_raw = $f{'(8) Other Names'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$f{"(8) Other Names"} // ""
MC/DC0%0/1
$f{"(8) Other Names"} // ""
$f{"(8) Other Names"}
Truth table50%1/2
A
A= $f{"(8) Other Names"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 4 | ▶ | my $nationality = $f{'(9) Nationality'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$f{"(9) Nationality"} // ""
MC/DC0%0/1
$f{"(9) Nationality"} // ""
$f{"(9) Nationality"}
Truth table50%1/2
A
A= $f{"(9) Nationality"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 4 | ▶ | my $passport_raw = $f{'(10) Passport Number'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$f{"(10) Passport Number"} // ""
MC/DC0%0/1
$f{"(10) Passport Number"} // ""
$f{"(10) Passport Number"}
Truth table50%1/2
A
A= $f{"(10) Passport Number"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 4 | ▶ | my $id_number = $f{'(11) Identification Card Number'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$f{"(11) Identification Card Number"} // ""
MC/DC0%0/1
$f{"(11) Identification Card Number"} // ""
$f{"(11) Identification Card Number"}
Truth table50%1/2
A
A= $f{"(11) Identification Card Number"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 4 | my @dob; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 4 | ▶ | @dob = ($dob_raw =~ /(\d{1,2}\.\d{1,2}\.\d{4})/g) if $dob_raw && $dob_raw ne '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dob_raw and $dob_raw ne "-"
MC/DC50%1/2
$dob_raw and $dob_raw ne "-"
$dob_raw
$dob_raw ne "-"
Truth table66%2/3
A and B
A= $dob_rawB= $dob_raw ne "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 4 | my @other_names; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 4 | ▶ | push @other_names, $other_names_raw if $other_names_raw && $other_names_raw ne '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$other_names_raw and $other_names_raw ne "-"
MC/DC50%1/2
$other_names_raw and $other_names_raw ne "-"
$other_names_raw
$other_names_raw ne "-"
Truth table66%2/3
A and B
A= $other_names_rawB= $other_names_raw ne "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | 4 | my @passports; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 4 | ▶ | @passports = map { trim($_) } split m{/}, $passport_raw if $passport_raw && $passport_raw ne '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$passport_raw and $passport_raw ne "-"
MC/DC0%0/2
$passport_raw and $passport_raw ne "-"
$passport_raw
$passport_raw ne "-"
Truth table33%1/3
A and B
A= $passport_rawB= $passport_raw ne "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 4 | my @ids; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 4 | ▶ | push @ids, $id_number if $id_number && $id_number ne '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$id_number and $id_number ne "-"
MC/DC50%1/2
$id_number and $id_number ne "-"
$id_number
$id_number ne "-"
Truth table66%2/3
A and B
A= $id_numberB= $id_number ne "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 4 | _process_sanction_entry( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | names => [$name, @other_names], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | date_of_birth => \@dob, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | place_of_birth => [$pob], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | nationality => [$nationality], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | national_id => \@ids, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | passport_no => \@passports, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 2 | ▶ | my $alias = $f{'(4) Alias'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$f{"(4) Alias"} // ""
MC/DC0%0/1
$f{"(4) Alias"} // ""
$f{"(4) Alias"}
Truth table50%1/2
A
A= $f{"(4) Alias"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 2 | ▶ | my $other_name = $f{'(5) Other Name'} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$f{"(5) Other Name"} // ""
MC/DC0%0/1
$f{"(5) Other Name"} // ""
$f{"(5) Other Name"}
Truth table50%1/2
A
A= $f{"(5) Other Name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 2 | my @names_list = ($name); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 2 | ▶ | push @names_list, $alias if $alias && $alias ne '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$alias and $alias ne "-"
MC/DC0%0/2
$alias and $alias ne "-"
$alias
$alias ne "-"
Truth table33%1/3
A and B
A= $aliasB= $alias ne "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 2 | ▶ | push @names_list, $other_name if $other_name && $other_name ne '-'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$other_name and $other_name ne "-"
MC/DC50%1/2
$other_name and $other_name ne "-"
$other_name
$other_name ne "-"
Truth table66%2/3
A and B
A= $other_nameB= $other_name ne "-"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 2 | _process_sanction_entry( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | names => \@names_list, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | date_of_birth => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | place_of_birth => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | nationality => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | national_id => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | passport_no => [], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 1 | updated => $publish_epoch, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | content => $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | =head2 _moha_xml_legacy | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | Parses the legacy TaggedPDF-doc XML format from MOHA sanctions list. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 11 | ▶ | sub _moha_xml_legacy { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_moha_xml_legacy: called CC=31 SCAR=39.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 11 | my ($raw_data, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | # Try to find the creation date | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 11 | my $publish_date; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | # Check if it's a standalone tag at the beginning | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 11 | ▶ | if (exists $data->{'xmp:CreateDate'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 0 | $publish_date = $data->{'xmp:CreateDate'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | # Check if it's nested within the rdf:Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | ▶ | elsif (exists $data->{'TaggedPDF-doc'} | |||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%3/9
exists $data->{"TaggedPDF-doc"} and exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"} and exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}{"rdf:RDF"} and exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}{"rdf:RDF"}{"rdf:Description"}
exists $data->{"TaggedPDF-doc"} and exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"} and exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}{"rdf:RDF"}
exists $data->{"TaggedPDF-doc"} and exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}
MC/DC0%0/4
exists $data->{"TaggedPDF-doc"} and exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"} and exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}{"rdf:RDF"} and exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}{"rdf:RDF"}{"rdf:Description"}
exists $data->{"TaggedPDF-doc"}
exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}
exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}{"rdf:RDF"}
exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}{"rdf:RDF"}{"rdf:Description"}
Truth table20%1/5
A and B and C and D
A= exists $data->{"TaggedPDF-doc"}B= exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}C= exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}{"rdf:RDF"}D= exists $data->{"TaggedPDF-doc"}{"x:xmpmeta"}{"rdf:RDF"}{"rdf:Description"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | && exists $data->{'TaggedPDF-doc'}{'x:xmpmeta'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | && exists $data->{'TaggedPDF-doc'}{'x:xmpmeta'}{'rdf:RDF'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | && exists $data->{'TaggedPDF-doc'}{'x:xmpmeta'}{'rdf:RDF'}{'rdf:Description'}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 11 | $publish_date = $data->{'TaggedPDF-doc'}{'x:xmpmeta'}{'rdf:RDF'}{'rdf:Description'}{'xmp:CreateDate'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | # If not found, try to extract it from the raw XML | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | elsif ($raw_data =~ /<xmp:CreateDate>([^<]+)<\/xmp:CreateDate>/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 0 | $publish_date = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 11 | my $publish_epoch = _date_to_epoch($publish_date); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 11 | ▶ | die "Invalid or missing creation date in XML\n" unless $publish_epoch; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | # Access the relevant table structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 11 | my $tables = $data->{'TaggedPDF-doc'}{'Document'}{'Table'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 11 | my $dataset = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | # Handle both array and single table formats | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 11 | ▶ | $tables = [$tables] if ref $tables eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 11 | foreach my $table (@$tables) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 110 | my $rows = $table->{'TBody'}{'TR'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 110 | ▶ | next unless ref $rows eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | # Determine if the first row is a header row | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 110 | my $start_index = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 110 | ▶ | if (@$rows > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 110 | my $first_row = $rows->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 110 | my @first_cells; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 110 | ▶ | if (exists $first_row->{'TH'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 110 | ▶ | if (ref $first_row->{'TH'} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | push @first_cells, @{$first_row->{'TH'}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 110 | push @first_cells, $first_row->{'TH'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 110 | ▶ | if (exists $first_row->{'TD'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 110 | ▶ | if (ref $first_row->{'TD'} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 110 | push @first_cells, @{$first_row->{'TD'}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 0 | push @first_cells, $first_row->{'TD'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | # Check if the first cell contains a header-like value | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 110 | ▶ | my $first_id = ref $first_cells[0]{'P'} eq 'ARRAY' ? join(' ', @{$first_cells[0]{'P'}}) : $first_cells[0]{'P'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 110 | ▶ | if ($first_id =~ /^\(1\)/ || $first_id =~ /^No\./) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$first_id =~ /^\(1\)/ or $first_id =~ /^No\./
MC/DC50%1/2
$first_id =~ /^\(1\)/ or $first_id =~ /^No\./
$first_id =~ /^\(1\)/
$first_id =~ /^No\./
Truth table66%2/3
A or B
A= $first_id =~ /^\(1\)/B= $first_id =~ /^No\./
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | # This is a header row, skip it | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 11 | $start_index = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | # Process all data rows | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 110 | foreach my $row (@$rows[$start_index .. $#$rows]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | # Get cells from a mix of TD and TH tags | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 1111 | my @all_cells; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | # Handle TH cells | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 1111 | ▶ | if (exists $row->{'TH'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 1111 | ▶ | if (ref $row->{'TH'} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 0 | push @all_cells, @{$row->{'TH'}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | 1111 | push @all_cells, $row->{'TH'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | # Handle TD cells | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 1111 | ▶ | if (exists $row->{'TD'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 1111 | ▶ | if (ref $row->{'TD'} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 1111 | push @all_cells, @{$row->{'TD'}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | 0 | push @all_cells, $row->{'TD'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 1111 | my $cells = \@all_cells; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 1111 | ▶ | next unless $cells && @$cells >= 11; # Need at least 11 cells for the required data | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cells and @$cells >= 11
MC/DC50%1/2
$cells and @$cells >= 11
$cells
@$cells >= 11
Truth table66%2/3
A and B
A= $cellsB= @$cells >= 11
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 847 | my $name = $cells->[2]{'P'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 847 | my $date_of_birth = $cells->[5]{'P'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 847 | my $other_name = $cells->[7]{'P'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 847 | my $place_of_birth = $cells->[6]{'P'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 847 | my $nationality = $cells->[8]{'P'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 847 | my $passport_number = $cells->[9]{'P'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 847 | my $identification_number = $cells->[10]{'P'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | # Trim whitespace from values | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 847 | for ($name, $date_of_birth, $other_name, $place_of_birth, $nationality, $passport_number, $identification_number) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 5929 | ▶ | $_ =~ s/^\s+|\s+$//g if defined $_; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | # if $name is array, convert it to a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 847 | ▶ | $name = join ' ', @$name if ref $name eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # if multiple aliases (other_name) are present, convert them to an array | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 847 | ▶ | my @other_name = ref $other_name eq 'ARRAY' ? @$other_name : ($other_name); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | # pass DOB as array | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 847 | ▶ | my @dob = ref $date_of_birth eq 'ARRAY' ? @$date_of_birth : ($date_of_birth); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 847 | _process_sanction_entry( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | names => [$name, @other_name], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | date_of_birth => [@dob], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | place_of_birth => [$place_of_birth], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | nationality => [$nationality], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | national_id => [$identification_number], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | passport_no => [$passport_number], | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 11 | updated => $publish_epoch, | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | content => $dataset, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | =head2 run | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | Fetches latest version of lists, and returns combined hash of successfully downloaded ones | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 13 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 13 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 13 | my $result = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 13 | my $config = config(%args); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 13 | ▶ | my $retries = $args{retries} // 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{"retries"} // 3
MC/DC0%0/1
$args{"retries"} // 3
$args{"retries"}
Truth table50%1/2
A
A= $args{"retries"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | # Ensure the handler subroutine reference is provided | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 13 | ▶ | die "Handler subroutine reference 'handler' is required" unless $args{handler}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 13 | my $handler = $args{handler}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 13 | foreach my $id (sort keys %$config) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 78 | my $source = $config->{$id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 78 | ▶ | die "Url is empty for $id\n" unless $source->{url}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | 77 | my $raw_data; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 77 | ▶ | if ($source->{url} =~ m/^file:\/\/(.*)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 67 | $raw_data = _entries_from_file($id); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | $raw_data = _entries_from_remote_src({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | id => $id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | source => $source->{url}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 10 | retries => $retries | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 67 | my $data = $source->{parser}->($raw_data); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | 67 | ▶ | if ($data->{updated} > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 67 | $result->{$id} = $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 67 | my $count = $data->{content}->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 67 | ▶ | print "Source $id: $count entries fetched \n" if $args{verbose}; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 67 | my $hash = _create_hash($data->{content}); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | 67 | $handler->($id, _clean_url($source->{url}), _epoch_to_date($data->{updated}), $hash, scalar $data->{content}->@*); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 78 | } catch ($e) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 11 | $result->{$id}->{error} = $e; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 13 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | =head2 _entries_from_file | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | Get the sanction entries from a file locally | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 67 | ▶ | sub _entries_from_file { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_entries_from_file: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 67 | my ($id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | 67 | my $entries; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 67 | ▶ | open my $fh, '<', "$1" or die "Can't open $id file $1 $!\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | 67 | $entries = do { local $/; <$fh> }; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 67 | close $fh; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | 67 | return $entries; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | =head2 _entries_from_remote_src | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | Get the sanction entries from a remote source includes retry mechanism | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | 10 | ▶ | sub _entries_from_remote_src { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_entries_from_remote_src: called CC=5 SCAR=17.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | 10 | my ($args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | 10 | my ($id, $src_url, $retries) = @{$args}{qw/ id source retries /}; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | 10 | ▶ | $retries //= 3; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$retries //= 3
MC/DC0%0/1
$retries //= 3
$retries
Truth table50%1/2
A
A= $retries
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | 10 | my $entries; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | 10 | my $error_log = 'Unknown Error'; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | 10 | my $ua = Mojo::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | 10 | $ua->connect_timeout(15); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | 10 | $ua->inactivity_timeout(60); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 10 | $ua->max_redirects(MAX_REDIRECTS); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | 10 | my $retry_counter = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 10 | ▶ | while ($retry_counter < $retries) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | 30 | $retry_counter++; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | 30 | my $resp = $ua->get($src_url); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | 0 | ▶ | die "File not downloaded for $id\n" if $resp->result->is_error; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | 0 | $entries = $resp->result->body; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | 0 | } catch ($e) { | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | 30 | $error_log = $e; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | 30 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 10 | ▶ | return $entries // die "An error occurred while fetching data from '$src_url' due to $error_log\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$entries // die("An error occurred while fetching data from '${src_url}' due to $error_log\n")
MC/DC0%0/1
$entries // die("An error occurred while fetching data from '${src_url}' due to $error_log\n")
$entries
Truth table50%1/2
A
A= $entries
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | =head2 _epoch_to_date | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | Converts an epoch timestamp to a date string in YYYY-MM-DD format. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | my $date = $fetcher->_epoch_to_date(1672444800); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | 72 | ▶ | sub _epoch_to_date { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_epoch_to_date: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | 72 | my $epoch = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | # Input validation | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 72 | ▶ | die "Epoch timestamp must be defined" unless defined $epoch; | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | # Convert epoch to DateTime object | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 71 | my $dt = DateTime->from_epoch(epoch => $epoch); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | # Return formatted date string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 70 | return $dt->ymd('-'); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | =head2 _clean_url | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | Removes specific query parameters from a URL. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | my $clean_url = $fetcher->_clean_url($url); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | 73 | ▶ | sub _clean_url { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clean_url: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | 73 | my $url = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | # Remove the token parameter from the URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | 73 | $url =~ s/[?&]token=[^&]+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | 73 | return $url; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | =head2 _create_hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | Converts the data to a string and creates a SHA-256 hash. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | my $hash = $fetcher->create_hash($data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | 72 | ▶ | sub _create_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_create_hash: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | 72 | my ($data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | # Convert the data to a JSON string | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | 72 | my $json_string = to_json( | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | $data, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | canonical => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | utf8 => 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | # Generate and return the SHA-256 hash | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | 72 | return sha256_hex($json_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||