Image/ExifTool/Geolocation.pm

filter: Statementstmt 72.7% 315 / 433 Branchbran 55.1% 170 / 308 Conditioncond 39.4% 62 / 157 MC/DCmcdc 21.7% 20 / 92 Subroutinesub 81.8% 9 / 11 Podpod 87.5% 7 / 8 totaltotal 57.7% 583 / 1009 CC 219 SCAR 58.0
CC
219
Cov
61%
Geolocate
464.7
GetEntry
456.7
AddEntry
89.3
CRAP 329.4
« Image/ExifTool/IPTC.pm ↑ Summary Image/ExifTool/Text.pm »
1 #------------------------------------------------------------------------------
2 # File: Geolocation.pm
3 #
4 # Description: Determine geolocation from GPS and visa-versa
5 #
6 # Revisions: 2024-03-03 - P. Harvey Created
7 # 2024-03-21 - PH Significant restructuring and addition of
8 # several new features.
9 #
10 # References: https://download.geonames.org/export/
11 #
12 # Notes: Set $Image::ExifTool::Geolocation::geoDir to override the
13 # default directory containing the database file Geolocation.dat
14 # and the GeoLang directory with the alternate language files.
15 # If set, this directory is
16 #
17 # AltNames.dat may be loaded from a different directory by
18 # specifying $Image::ExifTool::Geolocation::altDir. This
19 # database and has entries in the same order as Geolocation.dat,
20 # and each entry is a newline-separated list of alternate names
21 # terminated by a null byte. These alternate names are used
22 # only when searching for a city by name (eg. "Big Apple").
23 #
24 # Databases are based on data from geonames.org with a
25 # Creative Commons license, reformatted as follows in the
26 # Geolocation.dat file:
27 #
28 # Header:
29 # "GeolocationV.VV\tNNNN\n" (V.VV=version, NNNN=num city entries)
30 # "# <comment>\n"
31 # NNNN City entries:
32 # Offset Format Description
33 # 0 int16u - latitude high 16 bits (converted to 0-0x100000 range)
34 # 2 int8u - latitude low 4 bits, longitude low 4 bits
35 # 3 int16u - longitude high 16 bits
36 # 5 int8u - index of country in country list
37 # 6 int8u - 0xf0 = population E exponent (in format "N.Fe+0E"), 0x0f = population N digit
38 # 7 int16u - 0xf000 = population F digit, 0x0fff = index in region list (admin1)
39 # 9 int16u - v1.02: 0x7fff = index in subregion (admin2), 0x8000 = high bit of time zone
40 # 9 int16u - v1.03: index in subregion (admin2)
41 # 11 int8u - low byte of time zone index
42 # 12 int8u - 0x3f = feature code index (see below), v1.03: 0x80 = high bit of time zone
43 # 13 string - UTF8 City name, terminated by newline
44 # "\0\0\0\0\x01"
45 # Country entries:
46 # 1. 2-character country code
47 # 2. Country name, terminated by newline
48 # "\0\0\0\0\x02"
49 # Region entries:
50 # 1. Region name, terminated by newline
51 # "\0\0\0\0\x03"
52 # Subregion entries:
53 # 1. Subregion name, terminated by newline
54 # "\0\0\0\0\x04"
55 # Time zone entries:
56 # 1. Time zone name, terminated by newline
57 # "\0\0\0\0\x05" (feature codes added in v1.03)
58 # Feature codes:
59 # 1. Feature code, optional space-followed-by-feature-name, then newline
60 # "\0\0\0\0\0"
61 #
62 # Feature Codes v1.02: (see http://www.geonames.org/export/codes.html#P for descriptions)
63 #
64 # 0. Other 3. PPLA2 6. PPLA5 9. PPLF 12. PPLR 15. PPLX
65 # 1. PPL 4. PPLA3 7. PPLC 10. PPLG 13. PPLS
66 # 2. PPLA 5. PPLA4 8. PPLCH 11. PPLL 14. STLMT
67 #------------------------------------------------------------------------------
68  
69 package Image::ExifTool::Geolocation;
70  
71 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 1 ▶use vars qw($VERSION $geoDir $altDir $dbInfo);
Subroutine BEGIN: called CC=1 SCAR=0.0
73  
74 1 $VERSION = '1.10'; # (this is the module version number, not the database version)
75  
76 1 my $debug; # set to output processing time for testing
77  
78 sub ReadDatabase($);
79 sub SortDatabase($);
80 sub AddEntry(@);
81 sub GetEntry($;$$);
82 sub Geolocate($;$);
83  
84 1 my (@cityList, @countryList, @regionList, @subregionList, @timezoneList);
85 1 my (%countryNum, %regionNum, %subregionNum, %timezoneNum); # reverse lookups
86 1 my (@sortOrder, @altNames, %langLookup, $nCity, %featureCodes, %featureTypes);
87 1 my ($lastArgs, %lastFound, @lastByPop, @lastByLat); # cached city matches
88 1 my $dbVer = '1.03'; # database version number
89 1 my $sortedBy = 'Latitude';
90 1 my $pi = 3.1415926536;
91 1 my $earthRadius = 6371; # earth radius in km
92 # hard-coded feature codes for v1.02 database
93 1 my @featureCodes = qw(Other PPL PPLA PPLA2 PPLA3 PPLA4 PPLA5 PPLC
94 PPLCH PPLF PPLG PPLL PPLR PPLS STLMT PPLX);
95  
96 # get path name for database file from lib/Image/ExifTool/Geolocation.dat by default,
97 # or according to $Image::ExifTool::Geolocation::directory if specified
98 1 my $defaultDir = $INC{'Image/ExifTool/Geolocation.pm'};
99 1 ▶if ($defaultDir) {
Branch: 1 branch
BranchTrueFalseTotal
if ($defaultDir) { } 1 0 1
100 1 $defaultDir =~ s(/Geolocation\.pm$)();
101 } else {
102 0 $defaultDir = '.';
103 0 warn("Error getting Geolocation.pm directory\n");
104 }
105  
106 # read the Geolocation database unless $geoDir set to empty string
107 1 ▶unless (defined $geoDir and not $geoDir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Image::ExifTool::Geolocation::geoDir and not $Image::ExifTool::Geolocation::geoDir) 1 0 1
Condition33%1/3
defined $Image::ExifTool::Geolocation::geoDir and not $Image::ExifTool::Geolocation::geoDir
!ll&&!rl&&r
100
MC/DC0%0/2
defined $Image::ExifTool::Geolocation::geoDir and not $Image::ExifTool::Geolocation::geoDir
defined $Image::ExifTool::Geolocation::geoDir not $Image::ExifTool::Geolocation::geoDir
Truth table33%1/3
A and not(B)
A= defined $Image::ExifTool::Geolocation::geoDirB= not $Image::ExifTool::Geolocation::geoDir
ABresult
0X0
100
111
108 1 ▶ unless ($geoDir and ReadDatabase("$geoDir/Geolocation.dat")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Image::ExifTool::Geolocation::geoDir and &ReadDatabase("$Image::ExifTool::Geolocation::geoDir/Geolocation.dat")) 1 0 1
Condition33%1/3
$Image::ExifTool::Geolocation::geoDir and &ReadDatabase("$Image::ExifTool::Geolocation::geoDir/Geolocation.dat")
!ll&&!rl&&r
100
MC/DC0%0/2
$Image::ExifTool::Geolocation::geoDir and &ReadDatabase("$Image::ExifTool::Geolocation::geoDir/Geolocation.dat")
$Image::ExifTool::Geolocation::geoDir &ReadDatabase("$Image::ExifTool::Geolocation::geoDir/Geolocation.dat")
Truth table33%1/3
A and B
A= $Image::ExifTool::Geolocation::geoDirB= &ReadDatabase("$Image::ExifTool::Geolocation::geoDir/Geolocation.dat")
ABresult
0X0
100
111
109 1 ReadDatabase("$defaultDir/Geolocation.dat");
110 }
111 }
112  
113 # set directory for language files and alternate names
114 1 ▶$geoDir = $defaultDir unless defined $geoDir;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Image::ExifTool::Geolocation::geoDir 1 0 1
115 1 ▶if (not defined $altDir and $geoDir and -e "$geoDir/AltNames.dat") {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $Image::ExifTool::Geolocation::altDir and $Image::ExifTool::Geolocation::geoDir and -e "$Image::ExifTool::Geolocation::geoDir/AltNames.dat") 0 1 1
Condition33%2/6
not defined $Image::ExifTool::Geolocation::altDir and $Image::ExifTool::Geolocation::geoDir and -e "$Image::ExifTool::Geolocation::geoDir/AltNames.dat"
!ll&&!rl&&r
010
not defined $Image::ExifTool::Geolocation::altDir and $Image::ExifTool::Geolocation::geoDir
!ll&&!rl&&r
001
MC/DC0%0/3
not defined $Image::ExifTool::Geolocation::altDir and $Image::ExifTool::Geolocation::geoDir and -e "$Image::ExifTool::Geolocation::geoDir/AltNames.dat"
not defined $Image::ExifTool::Geolocation::altDir $Image::ExifTool::Geolocation::geoDir -e "$Image::ExifTool::Geolocation::geoDir/AltNames.dat"
Truth table25%1/4
not(A) and B and C
A= not defined $Image::ExifTool::Geolocation::altDirB= $Image::ExifTool::Geolocation::geoDirC= -e "$Image::ExifTool::Geolocation::geoDir/AltNames.dat"
ABCresult
0XX0
10X0
1100
1111
116 0 $altDir = $geoDir;
117 }
118  
119 # add user-defined entries to the database
120 1 ▶if (@Image::ExifTool::UserDefined::Geolocation) {
Branch: 1 branch
BranchTrueFalseTotal
if (@Image::ExifTool::UserDefined::Geolocation) 0 1 1
121 0 AddEntry(@$_) foreach @Image::ExifTool::UserDefined::Geolocation;
122 }
123  
124 #------------------------------------------------------------------------------
125 # Read Geolocation database
126 # Inputs: 0) database file name
127 # Returns: true on success
128 sub ReadDatabase($)
129 1 ▶{
Subroutine ReadDatabase: called CC=27 SCAR=34.5
Pod documented
130 1 my $datfile = shift;
131 # open geolocation database and verify header
132 1 ▶ open DATFILE, "< $datfile" or warn("Error reading $datfile\n"), return 0;
Branch: 1 branch
BranchTrueFalseTotal
open DATFILE, "< $datfile" or warn("Error reading $datfile\n"), (return 0) 1 0 1
133 1 binmode DATFILE;
134 1 my $line = <DATFILE>;
135 1 ▶ unless ($line =~ /^Geolocation(\d+\.\d+)\t(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($line =~ /^Geolocation(\d+\.\d+)\t(\d+)/) 0 1 1
136 0 warn("Bad format Geolocation database\n");
137 0 close(DATFILE);
138 0 return 0;
139 }
140 1 ($dbVer, $nCity) = ($1, $2);
141 1 ▶ if ($dbVer !~ /^1\.0[23]$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbVer =~ /^1\.0[23]$/) 0 1 1
142 0 ▶ my $which = $dbVer < 1.03 ? 'database' : 'ExifTool';
Branch: 1 branch
BranchTrueFalseTotal
$dbVer < 1.03 ? : 0 0 0
143 0 warn("Incompatible Geolocation database (update your $which)\n");
144 0 close(DATFILE);
145 0 return 0;
146 }
147 1 my $comment = <DATFILE>;
148 1 ▶ defined $comment and $comment =~ / (\d+) / or close(DATFILE), return 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $comment and $comment =~ / (\d+) / or close DATFILE, (return 0) 1 0 1
Condition33%1/3
defined $comment and $comment =~ / (\d+) /
!ll&&!rl&&r
001
MC/DC0%0/2
defined $comment and $comment =~ / (\d+) /
defined $comment $comment =~ / (\d+) /
Truth table33%1/3
A and B
A= defined $commentB= $comment =~ / (\d+) /
ABresult
0X0
100
111
149 1 $dbInfo = "$datfile v$dbVer: $nCity cities with population > $1";
150 1 my $isUserDefined = @Image::ExifTool::UserDefined::Geolocation;
151  
152 1 undef @altNames; # reset altNames
153  
154 # read city database
155 1 undef @cityList;
156 1 my $i = 0;
157 1 for (;;) {
158 116055 $line = <DATFILE>;
159 116055 ▶ last if length($line) == 6 and $line =~ /\0\0\0\0/;
Branch: 1 branch
BranchTrueFalseTotal
if length $line == 6 and $line =~ /\0\0\0\0/ 1 116054 116055
Condition100%3/3
length $line == 6 and $line =~ /\0\0\0\0/
!ll&&!rl&&r
1154266281
MC/DC100%2/2
length $line == 6 and $line =~ /\0\0\0\0/
length $line == 6 $line =~ /\0\0\0\0/
Truth table100%3/3
A and B
A= length $line == 6B= $line =~ /\0\0\0\0/
ABresult
0X0
100
111
160 116054 ▶ $line .= <DATFILE> while length($line) < 14;
Branch: 1 branch
BranchTrueFalseTotal
length $line < 14 and do { $line .= <DATFILE> } 4545 116054 120599
161 116054 chomp $line;
162 116054 push @cityList, $line;
163 }
164 1 ▶ @cityList == $nCity or warn("Bad number of entries in Geolocation database\n"), return 0;
Branch: 1 branch
BranchTrueFalseTotal
@cityList == $nCity or warn("Bad number of entries in Geolocation database\n"), (return 0) 1 0 1
165 # read countries
166 1 for (;;) {
167 239 $line = <DATFILE>;
168 239 ▶ last if length($line) == 6 and $line =~ /\0\0\0\0/;
Branch: 1 branch
BranchTrueFalseTotal
if length $line == 6 and $line =~ /\0\0\0\0/ 1 238 239
Condition66%2/3
length $line == 6 and $line =~ /\0\0\0\0/
!ll&&!rl&&r
23801
MC/DC50%1/2
length $line == 6 and $line =~ /\0\0\0\0/
length $line == 6 $line =~ /\0\0\0\0/
Truth table66%2/3
A and B
A= length $line == 6B= $line =~ /\0\0\0\0/
ABresult
0X0
100
111
169 238 chomp $line;
170 238 push @countryList, $line;
171 238 ▶ $countryNum{lc substr($line,0,2)} = $#countryList if $isUserDefined;
Branch: 1 branch
BranchTrueFalseTotal
if $isUserDefined 0 238 238
172 }
173 # read regions
174 1 for (;;) {
175 3756 $line = <DATFILE>;
176 3756 ▶ last if length($line) == 6 and $line =~ /\0\0\0\0/;
Branch: 1 branch
BranchTrueFalseTotal
if length $line == 6 and $line =~ /\0\0\0\0/ 1 3755 3756
Condition100%3/3
length $line == 6 and $line =~ /\0\0\0\0/
!ll&&!rl&&r
34942611
MC/DC100%2/2
length $line == 6 and $line =~ /\0\0\0\0/
length $line == 6 $line =~ /\0\0\0\0/
Truth table100%3/3
A and B
A= length $line == 6B= $line =~ /\0\0\0\0/
ABresult
0X0
100
111
177 3755 chomp $line;
178 3755 push @regionList, $line;
179 3755 ▶ $regionNum{lc $line} = $#regionList if $isUserDefined;
Branch: 1 branch
BranchTrueFalseTotal
if $isUserDefined 0 3755 3755
180 }
181 # read subregions
182 1 for (;;) {
183 31948 $line = <DATFILE>;
184 31948 ▶ last if length($line) == 6 and $line =~ /\0\0\0\0/;
Branch: 1 branch
BranchTrueFalseTotal
if length $line == 6 and $line =~ /\0\0\0\0/ 1 31947 31948
Condition100%3/3
length $line == 6 and $line =~ /\0\0\0\0/
!ll&&!rl&&r
309609871
MC/DC100%2/2
length $line == 6 and $line =~ /\0\0\0\0/
length $line == 6 $line =~ /\0\0\0\0/
Truth table100%3/3
A and B
A= length $line == 6B= $line =~ /\0\0\0\0/
ABresult
0X0
100
111
185 31947 chomp $line;
186 31947 push @subregionList, $line;
187 31947 ▶ $subregionNum{lc $line} = $#subregionList if $isUserDefined;
Branch: 1 branch
BranchTrueFalseTotal
if $isUserDefined 0 31947 31947
188 }
189 # read time zones
190 1 for (;;) {
191 380 $line = <DATFILE>;
192 380 ▶ last if length($line) == 6 and $line =~ /\0\0\0\0/;
Branch: 1 branch
BranchTrueFalseTotal
if length $line == 6 and $line =~ /\0\0\0\0/ 1 379 380
Condition66%2/3
length $line == 6 and $line =~ /\0\0\0\0/
!ll&&!rl&&r
37901
MC/DC50%1/2
length $line == 6 and $line =~ /\0\0\0\0/
length $line == 6 $line =~ /\0\0\0\0/
Truth table66%2/3
A and B
A= length $line == 6B= $line =~ /\0\0\0\0/
ABresult
0X0
100
111
193 379 chomp $line;
194 379 push @timezoneList, $line;
195 379 ▶ $timezoneNum{lc $line} = $#timezoneList if $isUserDefined;
Branch: 1 branch
BranchTrueFalseTotal
if $isUserDefined 0 379 379
196 }
197 # read feature codes if available
198 1 ▶ if ($line eq "\0\0\0\0\x05\n") {
Branch: 1 branch
BranchTrueFalseTotal
if ($line eq "\0\0\0\0\5\n") 1 0 1
199 1 undef @featureCodes;
200 1 for (;;) {
201 20 $line = <DATFILE>;
202 20 ▶ last if length($line) == 6 and $line =~ /\0\0\0\0/;
Branch: 1 branch
BranchTrueFalseTotal
if length $line == 6 and $line =~ /\0\0\0\0/ 1 19 20
Condition100%3/3
length $line == 6 and $line =~ /\0\0\0\0/
!ll&&!rl&&r
1811
MC/DC100%2/2
length $line == 6 and $line =~ /\0\0\0\0/
length $line == 6 $line =~ /\0\0\0\0/
Truth table100%3/3
A and B
A= length $line == 6B= $line =~ /\0\0\0\0/
ABresult
0X0
100
111
203 19 chomp $line;
204 19 ▶ $featureTypes{$line} = $1 if $line =~ s/ (.*)//;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ s/ (.*)// 18 1 19
205 19 push @featureCodes, $line;
206 }
207 }
208 1 close DATFILE;
209 # initialize featureCodes lookup
210 1 $i = 0;
211 1 %featureCodes = map { lc($_) => $i++ } @featureCodes;
212 1 return 1;
213 }
214  
215 #------------------------------------------------------------------------------
216 # Read alternate-names database
217 # Returns: True on success
218 # Notes: Must be called after ReadDatabase(). Resets $altDir on exit.
219 sub ReadAltNames()
220 0 ▶{
Subroutine ReadAltNames: not called CC=6 SCAR=37.4
Pod documented
221 0 my $success;
222 0 ▶ if ($altDir and $nCity) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Image::ExifTool::Geolocation::altDir and $nCity) 0 0 0
Condition0%0/3
$Image::ExifTool::Geolocation::altDir and $nCity
!ll&&!rl&&r
000
MC/DC0%0/2
$Image::ExifTool::Geolocation::altDir and $nCity
$Image::ExifTool::Geolocation::altDir $nCity
Truth table0%0/3
A and B
A= $Image::ExifTool::Geolocation::altDirB= $nCity
ABresult
0X0
100
111
223 0 ▶ if (open ALTFILE, "< $altDir/AltNames.dat") {
Branch: 1 branch
BranchTrueFalseTotal
if (open ALTFILE, "< $Image::ExifTool::Geolocation::altDir/AltNames.dat") { } 0 0 0
224 0 binmode ALTFILE;
225 0 local $/ = "\0";
226 0 my $i = 0;
227 0 ▶ while (<ALTFILE>) { chop; $altNames[$i++] = $_; }
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ALTFILE)) 0 0 0
228 0 close ALTFILE;
229 0 ▶ if ($i == $nCity) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == $nCity) { } 0 0 0
230 0 $success = 1;
231 } else {
232 0 warn("Bad number of entries in AltNames database\n");
233 0 undef @altNames;
234 }
235 } else {
236 0 warn "Error reading $altDir/AltNames.dat\n";
237 }
238 0 undef $altDir;
239 }
240 0 return $success;
241 }
242  
243 #------------------------------------------------------------------------------
244 # Clear last city matches cache
245 sub ClearLastMatches()
246 4 ▶{
Subroutine ClearLastMatches: called CC=1 SCAR=0.0
Pod undocumented
247 4 undef $lastArgs; # arguments in last call to Geolocate
248 4 undef %lastFound; # keys are last matching city numbers, values are population codes
249 4 undef @lastByPop; # last matching city numbers ordered by population
250 4 undef @lastByLat; # last matching city numbers ordered by latitude
251 }
252  
253 #------------------------------------------------------------------------------
254 # Sort database by specified field
255 # Inputs: 0) Field name to sort (Latitude,City,Country)
256 # Returns: 1 on success
257 sub SortDatabase($)
258 6 ▶{
Subroutine SortDatabase: called CC=6 SCAR=25.0
Pod documented
259 6 my $field = shift;
260 6 ▶ return 1 if $field eq $sortedBy; # already sorted?
Branch: 1 branch
BranchTrueFalseTotal
if $field eq $sortedBy 5 1 6
261 1 undef @sortOrder;
262 1 ▶ if ($field eq 'Latitude') {
Branch: 3 branches
BranchTrueFalseTotal
if ($field eq 'Latitude') { } 1 0 1
elsif ($field eq 'City') { } 0 0 0
elsif ($field eq 'Country') { } 0 0 0
263 1 @sortOrder = sort { $cityList[$a] cmp $cityList[$b] } 0..$#cityList;
264 } elsif ($field eq 'City') {
265 0 @sortOrder = sort { substr($cityList[$a],13) cmp substr($cityList[$b],13) } 0..$#cityList;
266 } elsif ($field eq 'Country') {
267 0 my %lkup;
268 0 foreach (0..$#cityList) {
269 0 my $city = substr($cityList[$_],13);
270 0 my $ctry = substr($countryList[ord substr($cityList[$_],5,1)], 2);
271 0 $lkup{$_} = "$ctry $city";
272 }
273 0 @sortOrder = sort { $lkup{$a} cmp $lkup{$b} } 0..$#cityList;
274 } else {
275 0 return 0;
276 }
277 1 $sortedBy = $field;
278 1 ClearLastMatches();
279 1 return 1;
280 }
281  
282 #------------------------------------------------------------------------------
283 # Add cities to the Geolocation database
284 # Inputs: 0-8) city,region,subregion,country_code,country,timezone,feature_code,population,lat,lon,altNames
285 # eg. AddEntry('Sinemorets','Burgas','Obshtina Tsarevo','BG','Bulgaria','Europe/Sofia','',400,42.06115,27.97833)
286 # Returns: true on success, otherwise issues warning
287 sub AddEntry(@)
288 1 ▶{
Subroutine AddEntry: called CC=27 SCAR=44.9
Pod documented
289 1 my ($city, $region, $subregion, $cc, $country, $timezone, $fc, $pop, $lat, $lon, $altNames) = @_;
290 1 ▶ @_ < 10 and warn("Too few arguments in $city definition (check for updated format)\n"), return 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ < 10 and warn("Too few arguments in $city definition (check for updated format)\n"), (return 0) 0 1 1
291 1 ▶ length($cc) != 2 and warn("Country code '${cc}' is not 2 characters\n"), return 0;
Branch: 1 branch
BranchTrueFalseTotal
length $cc != 2 and warn("Country code '${cc}' is not 2 characters\n"), (return 0) 0 1 1
292 1 ▶ $featureTypes{$fc} = $1 if $fc =~ s/ (.*)//;
Branch: 1 branch
BranchTrueFalseTotal
if $fc =~ s/ (.*)// 0 1 1
293 1 my $fn = $featureCodes{lc $fc};
294 1 ▶ unless (defined $fn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $fn) 1 0 1
295 1 ▶ if ($dbVer eq '1.02' or @featureCodes > 0x3f or not length $fc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbVer eq '1.02' or @featureCodes > 63 or not length $fc) { } 1 0 1
Condition33%2/6
$dbVer eq "1.02" or @featureCodes > 63 or not length $fc
l!l&&r!l&&!r
010
$dbVer eq "1.02" or @featureCodes > 63
l!l&&r!l&&!r
001
MC/DC0%0/3
$dbVer eq "1.02" or @featureCodes > 63 or not length $fc
$dbVer eq "1.02" @featureCodes > 63 not length $fc
Truth table25%1/4
A or B or not(C)
A= $dbVer eq "1.02"B= @featureCodes > 63C= not length $fc
ABCresult
1XX1
01X1
0011
0000
296 1 $fn = 0;
297 } else {
298 0 push @featureCodes, uc($fc);
299 0 $featureCodes{lc $fc} = $fn = $#featureCodes;
300 }
301 }
302 1 chomp $lon; # (just in case it was read from file)
303 # create reverse lookups for country/region/subregion/timezone if not done already
304 # (eg. if the entries are being added manually instead of via UserDefined::Geolocation)
305 1 ▶ unless (%countryNum) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%countryNum) 1 0 1
306 1 my $i;
307 1 $i = 0; $countryNum{lc substr($_,0,2)} = $i++ foreach @countryList;
308 1 $i = 0; $regionNum{lc $_} = $i++ foreach @regionList;
309 1 $i = 0; $subregionNum{lc $_} = $i++ foreach @subregionList;
310 1 $i = 0; $timezoneNum{lc $_} = $i++ foreach @timezoneList;
311 }
312 1 my $cn = $countryNum{lc $cc};
313 1 ▶ unless (defined $cn) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $cn) { } 1 0 1
if (do { $country }) 0 1 1
314 0 ▶ $#countryList >= 0xff and warn("AddEntry: Too many countries\n"), return 0;
Branch: 1 branch
BranchTrueFalseTotal
$#countryList >= 255 and warn("AddEntry: Too many countries\n"), (return 0) 0 0 0
315 0 push @countryList, "$cc$country";
316 0 $cn = $countryNum{lc $cc} = $#countryList;
317 0 } elsif ($country) {
318 0 $countryList[$cn] = "$cc$country"; # (override existing country name)
319 }
320 1 my $tn = $timezoneNum{lc $timezone};
321 1 ▶ unless (defined $tn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tn) 0 1 1
322 0 ▶ $#timezoneList >= 0x1ff and warn("AddEntry: Too many time zones\n"), return 0;
Branch: 1 branch
BranchTrueFalseTotal
$#timezoneList >= 511 and warn("AddEntry: Too many time zones\n"), (return 0) 0 0 0
323 0 push @timezoneList, $timezone;
324 0 $tn = $timezoneNum{lc $timezone} = $#timezoneList;
325 }
326 1 my $rn = $regionNum{lc $region};
327 1 ▶ unless (defined $rn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $rn) 0 1 1
328 0 ▶ $#regionList >= 0xfff and warn("AddEntry: Too many regions\n"), return 0;
Branch: 1 branch
BranchTrueFalseTotal
$#regionList >= 4095 and warn("AddEntry: Too many regions\n"), (return 0) 0 0 0
329 0 push @regionList, $region;
330 0 $rn = $regionNum{lc $region} = $#regionList;
331 }
332 1 my $sn = $subregionNum{lc $subregion};
333 1 ▶ unless (defined $sn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $sn) 0 1 1
334 0 ▶ my $max = $dbVer eq '1.02' ? 0x7fff : 0xffff;
Branch: 1 branch
BranchTrueFalseTotal
$dbVer eq '1.02' ? : 0 0 0
335 0 ▶ $#subregionList >= $max and warn("AddEntry: Too many subregions\n"), return 0;
Branch: 1 branch
BranchTrueFalseTotal
$#subregionList >= $max and warn("AddEntry: Too many subregions\n"), (return 0) 0 0 0
336 0 push @subregionList, $subregion;
337 0 $sn = $subregionNum{lc $subregion} = $#subregionList;
338 }
339 1 $pop = sprintf('%.1e',$pop); # format: "3.1e+04" or "3.1e+004"
340 # pack CC index, population and region index into a 32-bit integer
341 1 my $code = ($cn << 24) | (substr($pop,-1,1)<<20) | (substr($pop,0,1)<<16) | (substr($pop,2,1)<<12) | $rn;
342 # store high bit of timezone index
343 1 ▶ if ($tn > 255) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tn > 255) 1 0 1
344 1 ▶ if ($dbVer eq '1.02') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbVer eq '1.02') { } 0 1 1
345 0 $sn |= 0x8000;
346 } else {
347 1 $fn |= 0x80;
348 }
349 1 $tn -= 256;
350 }
351 1 $lat = int(($lat + 90) / 180 * 0x100000 + 0.5) & 0xfffff;
352 1 $lon = int(($lon + 180) / 360 * 0x100000 + 0.5) & 0xfffff;
353 1 my $hdr = pack('nCnNnCC', $lat>>4, (($lat&0x0f)<<4)|($lon&0x0f), $lon>>4, $code, $sn, $tn, $fn);
354 1 push @cityList, "$hdr$city";
355 # add altNames entry if provided
356 1 ▶ if ($altNames) {
Branch: 1 branch
BranchTrueFalseTotal
if ($altNames) 1 0 1
357 1 chomp $altNames; # (just in case)
358 1 $altNames =~ tr/,/\n/;
359 # add any more arguments in case altNames were passed separately (undocumented)
360 1 foreach (11..$#_) {
361 0 chomp $_[$_];
362 0 $altNames .= "\n$_[$_]";
363 }
364 1 $altNames[$#cityList] = $altNames;
365 }
366 1 $sortedBy = '';
367 1 undef $lastArgs; # (faster than ClearLastArgs)
368 1 return 1;
369 }
370  
371 #------------------------------------------------------------------------------
372 # Unpack entry in database
373 # Inputs: 0) entry number or index into sorted database,
374 # 1) optional language code, 2) flag to use index into sorted database
375 # Returns: 0-10) city,region,subregion,country_code,country,timezone,
376 # feature_code,pop,lat,lon,feature_type
377 sub GetEntry($;$$)
378 9 ▶{
Subroutine GetEntry: called CC=32 SCAR=61.2
Pod documented
379 9 my ($entryNum, $lang, $sort) = @_;
380 9 ▶ return() if $entryNum > $#cityList;
Branch: 1 branch
BranchTrueFalseTotal
if $entryNum > $#cityList 0 9 9
381 9 ▶ $entryNum = $sortOrder[$entryNum] if $sort and @sortOrder > $entryNum;
Branch: 1 branch
BranchTrueFalseTotal
if $sort and @sortOrder > $entryNum 0 9 9
Condition33%1/3
$sort and @sortOrder > $entryNum
!ll&&!rl&&r
900
MC/DC0%0/2
$sort and @sortOrder > $entryNum
$sort @sortOrder > $entryNum
Truth table33%1/3
A and B
A= $sortB= @sortOrder > $entryNum
ABresult
0X0
100
111
382 9 my ($lt,$f,$ln,$code,$sn,$tn,$fn) = unpack('nCnNnCC', $cityList[$entryNum]);
383 9 my $city = substr($cityList[$entryNum],13);
384 9 my $ctry = $countryList[$code >> 24];
385 9 my $rgn = $regionList[$code & 0x0fff];
386 9 ▶ if ($dbVer eq '1.02') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dbVer eq '1.02') { } 0 9 9
387 0 ▶ $sn & 0x8000 and $tn += 256, $sn &= 0x7fff;
Branch: 1 branch
BranchTrueFalseTotal
$sn & 32768 and $tn += 256, $sn &= 32767 0 0 0
388 } else {
389 9 ▶ $fn & 0x80 and $tn += 256;
Branch: 1 branch
BranchTrueFalseTotal
$fn & 128 and $tn += 256 9 0 9
390 }
391 9 my $sub = $subregionList[$sn];
392 # convert population digits back into exponent format
393 9 my $pop = (($code>>16 & 0x0f) . '.' . ($code>>12 & 0x0f) . 'e+' . ($code>>20 & 0x0f)) + 0;
394 9 $lt = sprintf('%.4f', (($lt<<4)|($f >> 4)) * 180 / 0x100000 - 90);
395 9 $ln = sprintf('%.4f', (($ln<<4)|($f & 0x0f))* 360 / 0x100000 - 180);
396 9 ▶ my $fc = $featureCodes[$fn & 0x3f] || 'Other';
Condition50%1/2
$featureCodes[$fn & 63] || 'Other'
l!l
90
MC/DC0%0/1
$featureCodes[$fn & 63] || 'Other'
$featureCodes[$fn & 63]
Truth table50%1/2
A
A= $featureCodes[$fn & 63]
Aresult
11
00
397 9 my $cc = substr($ctry, 0, 2);
398 9 my $country = substr($ctry, 2);
399 9 my $ft = $featureTypes{$fc};
400 9 ▶ if ($lang and $lang ne 'en') {
Branch: 1 branch
BranchTrueFalseTotal
if ($lang and $lang ne "en") 0 9 9
Condition33%1/3
$lang and $lang ne "en"
!ll&&!rl&&r
090
MC/DC0%0/2
$lang and $lang ne "en"
$lang $lang ne "en"
Truth table33%1/3
A and B
A= $langB= $lang ne "en"
ABresult
0X0
100
111
401 0 my $xlat = $langLookup{$lang};
402 # load language lookups if not done already
403 0 ▶ if (not defined $xlat) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $xlat) 0 0 0
404 0 unshift @INC, $geoDir; # make sure $geoDir is first in path
405 0 ▶ if (eval "require 'GeoLang/$lang.pm'") {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require 'GeoLang/$lang.pm'") 0 0 0
406 0 my $trans = "Image::ExifTool::GeoLang::${lang}::Translate";
407 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
408 0 ▶ $xlat = \%$trans if %$trans;
Branch: 1 branch
BranchTrueFalseTotal
if %$trans 0 0 0
409 }
410 0 shift @INC;
411 # read user-defined language translations
412 0 ▶ if (%Image::ExifTool::Geolocation::geoLang) {
Branch: 1 branch
BranchTrueFalseTotal
if (%Image::ExifTool::Geolocation::geoLang) 0 0 0
413 0 my $userLang = $Image::ExifTool::Geolocation::geoLang{$lang};
414 0 ▶ if ($userLang and ref($userLang) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($userLang and ref $userLang eq "HASH") 0 0 0
Condition0%0/3
$userLang and ref $userLang eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$userLang and ref $userLang eq "HASH"
$userLang ref $userLang eq "HASH"
Truth table0%0/3
A and B
A= $userLangB= ref $userLang eq "HASH"
ABresult
0X0
100
111
415 0 ▶ if ($xlat) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xlat) { } 0 0 0
416 # add user-defined entries to main lookup
417 0 $$xlat{$_} = $$userLang{$_} foreach keys %$userLang;
418 } else {
419 0 $xlat = $userLang;
420 }
421 }
422 }
423 0 ▶ $langLookup{$lang} = $xlat || 0;
Condition0%0/2
$xlat || 0
l!l
00
MC/DC0%0/1
$xlat || 0
$xlat
Truth table0%0/2
A
A= $xlat
Aresult
11
00
424 }
425 0 ▶ if ($xlat) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xlat) 0 0 0
426 0 my $r2 = $rgn;
427 # City-specific: "CCRgn,Sub,City", "CCRgn,City", "CC,City", ",City"
428 # Subregion-specific: "CCRgn,Sub,"
429 # Region-specific: "CCRgn,"
430 # Country-specific: "CC,"
431 $city = $$xlat{"$cc$r2,$sub,$city"} || $$xlat{"$cc$r2,$city"} ||
432 0 ▶ $$xlat{"$cc,$city"} || $$xlat{",$city"} || $$xlat{$city} || $city;
Condition0%0/15
$$xlat{"$cc$r2,$sub,$city"} || $$xlat{"$cc$r2,$city"} || $$xlat{"$cc,$city"} || $$xlat{",$city"} || $xlat->{$city} || $city
l!l&&r!l&&!r
000
$$xlat{"$cc$r2,$sub,$city"} or $$xlat{"$cc$r2,$city"} or $$xlat{"$cc,$city"} or $$xlat{",$city"} or $xlat->{$city}
l!l&&r!l&&!r
000
$$xlat{"$cc$r2,$sub,$city"} or $$xlat{"$cc$r2,$city"} or $$xlat{"$cc,$city"} or $$xlat{",$city"}
l!l&&r!l&&!r
000
$$xlat{"$cc$r2,$sub,$city"} or $$xlat{"$cc$r2,$city"} or $$xlat{"$cc,$city"}
l!l&&r!l&&!r
000
$$xlat{"$cc$r2,$sub,$city"} or $$xlat{"$cc$r2,$city"}
l!l&&r!l&&!r
000
MC/DC0%0/6
$$xlat{"$cc$r2,$sub,$city"} || $$xlat{"$cc$r2,$city"} || $$xlat{"$cc,$city"} || $$xlat{",$city"} || $xlat->{$city} || $city
$$xlat{"$cc$r2,$sub,$city"} $$xlat{"$cc$r2,$city"} $$xlat{"$cc,$city"} $$xlat{",$city"} $xlat->{$city} $city
Truth table0%0/7
A or B or C or D or E || F
A= $$xlat{"$cc$r2,$sub,$city"}B= $$xlat{"$cc$r2,$city"}C= $$xlat{"$cc,$city"}D= $$xlat{",$city"}E= $xlat->{$city}F= $city
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
433 0 ▶ $sub = $$xlat{"$cc$rgn,$sub,"} || $$xlat{$sub} || $sub;
Condition0%0/6
$$xlat{"$cc$rgn,$sub,"} || $xlat->{$sub} || $sub
l!l&&r!l&&!r
000
$$xlat{"$cc$rgn,$sub,"} or $xlat->{$sub}
l!l&&r!l&&!r
000
MC/DC0%0/3
$$xlat{"$cc$rgn,$sub,"} || $xlat->{$sub} || $sub
$$xlat{"$cc$rgn,$sub,"} $xlat->{$sub} $sub
Truth table0%0/4
A or B || C
A= $$xlat{"$cc$rgn,$sub,"}B= $xlat->{$sub}C= $sub
ABCresult
1XX1
01X1
0011
0000
434 0 ▶ $rgn = $$xlat{"$cc$rgn,"} || $$xlat{$rgn} || $rgn;
Condition0%0/6
$$xlat{"$cc$rgn,"} || $xlat->{$rgn} || $rgn
l!l&&r!l&&!r
000
$$xlat{"$cc$rgn,"} or $xlat->{$rgn}
l!l&&r!l&&!r
000
MC/DC0%0/3
$$xlat{"$cc$rgn,"} || $xlat->{$rgn} || $rgn
$$xlat{"$cc$rgn,"} $xlat->{$rgn} $rgn
Truth table0%0/4
A or B || C
A= $$xlat{"$cc$rgn,"}B= $xlat->{$rgn}C= $rgn
ABCresult
1XX1
01X1
0011
0000
435 0 ▶ $country = $$xlat{"$cc,"} || $$xlat{$country} || $country;
Condition0%0/6
$$xlat{"$cc,"} || $xlat->{$country} || $country
l!l&&r!l&&!r
000
$$xlat{"$cc,"} or $xlat->{$country}
l!l&&r!l&&!r
000
MC/DC0%0/3
$$xlat{"$cc,"} || $xlat->{$country} || $country
$$xlat{"$cc,"} $xlat->{$country} $country
Truth table0%0/4
A or B || C
A= $$xlat{"$cc,"}B= $xlat->{$country}C= $country
ABCresult
1XX1
01X1
0011
0000
436 0 ▶ $ft = $$xlat{$fc} if $$xlat{$fc};
Branch: 1 branch
BranchTrueFalseTotal
if $xlat->{$fc} 0 0 0
437 }
438 }
439 9 return($city,$rgn,$sub,$cc,$country,$timezoneList[$tn],$fc,$pop,$lt,$ln,$ft);
440 }
441  
442 #------------------------------------------------------------------------------
443 # Get alternate names for specified database entry
444 # Inputs: 0) entry number or index into sorted database, 1) sort flag
445 # Returns: comma-separated list of alternate names, or empty string if no names
446 # Notes: ReadAltNames() must be called before this
447 sub GetAltNames($;$)
448 0 ▶{
Subroutine GetAltNames: not called CC=4 SCAR=30.0
Pod documented
449 0 my ($entryNum, $sort) = @_;
450 0 ▶ $entryNum = $sortOrder[$entryNum] if $sort and @sortOrder > $entryNum;
Branch: 1 branch
BranchTrueFalseTotal
if $sort and @sortOrder > $entryNum 0 0 0
Condition0%0/3
$sort and @sortOrder > $entryNum
!ll&&!rl&&r
000
MC/DC0%0/2
$sort and @sortOrder > $entryNum
$sort @sortOrder > $entryNum
Truth table0%0/3
A and B
A= $sortB= @sortOrder > $entryNum
ABresult
0X0
100
111
451 0 ▶ my $alt = $altNames[$entryNum] or return '';
Branch: 1 branch
BranchTrueFalseTotal
my $alt = $altNames[$entryNum] or return "" 0 0 0
452 0 $alt =~ tr/\n/,/;
453 0 return $alt;
454 }
455  
456 #------------------------------------------------------------------------------
457 # Look up lat,lon or city in geolocation database
458 # Inputs: 0) "lat,lon", "city,region,country", etc, (city must be first)
459 # 1) options hash reference (or undef for no options)
460 # Options: GeolocMinPop, GeolocMaxDist, GeolocMulti, GeolocFeature, GeolocAltNames,
461 # GeolocNearby
462 # Returns: 0) Reference to list of indices for matching cities, or undef for no matches
463 # 1) Reference to list of distance/bearing pairs, or undef if no GPS
464 # In scalar context returns list of indices only
465 sub Geolocate($;$)
466 8 ▶{
Subroutine Geolocate: called CC=123 SCAR=61.4
Pod documented
467 8 my ($arg, $opts) = @_;
468 8 my ($city, @exact, %regex, @multiCity, $other, $idx, @cargs);
469 8 my ($minPop, $minDistU, $minDistC, @matchParms, @coords, %fcOK, $both);
470 8 my ($pop, $maxDist, $multi, $fcodes, $altNames, @startTime);
471  
472 $opts and ($pop, $maxDist, $multi, $fcodes, $altNames) =
473 8 ▶ @$opts{qw(GeolocMinPop GeolocMaxDist GeolocMulti GeolocFeature GeolocAltNames)};
Branch: 1 branch
BranchTrueFalseTotal
$opts and () = @$opts{"GeolocMinPop", "GeolocMaxDist", "GeolocMulti", "GeolocFeature", "GeolocAltNames"} 8 0 8
474  
475 8 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 8 8
476 0 require Time::HiRes;
477 0 @startTime = Time::HiRes::gettimeofday();
478 }
479 8 ▶ @cityList or warn('No Geolocation database'), return();
Branch: 1 branch
BranchTrueFalseTotal
@cityList or warn("No Geolocation database"), (return ()) 8 0 8
480 # make population code for comparing with 2 bytes at offset 6 in database
481 8 ▶ if ($pop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pop) 3 5 8
482 3 $pop = sprintf('%.1e', $pop);
483 3 $minPop = chr((substr($pop,-1,1)<<4) | (substr($pop,0,1))) . chr(substr($pop,2,1)<<4);
484 }
485 8 ▶ if ($fcodes) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fcodes) 1 7 8
486 1 my $neg = $fcodes =~ s/^-//;
487 1 my @fcodes = split /\s*,-?\s*/, lc $fcodes; # (allow leading dash on subsequent codes)
488 1 ▶ if ($neg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($neg) { } 1 0 1
489 1 $fcOK{$_} = 1 foreach 0..$#featureCodes;
490 1 ▶ defined $featureCodes{$_} and delete $fcOK{$featureCodes{$_}} foreach @fcodes;
Branch: 1 branch
BranchTrueFalseTotal
defined $featureCodes{$_} and delete $fcOK{$featureCodes{$_}} 1 0 1
491 } else {
492 0 ▶ defined $featureCodes{$_} and $fcOK{$featureCodes{$_}} = 1 foreach @fcodes;
Branch: 1 branch
BranchTrueFalseTotal
defined $featureCodes{$_} and $fcOK{$featureCodes{$_}} = 1 0 0 0
493 }
494 }
495 #
496 # process input argument
497 #
498 8 my $num = 1;
499 8 $arg =~ s/^\s+//; $arg =~ s/\s+$//; # remove leading/trailing spaces
500 8 my @args = split /\s*,\s*/, $arg;
501 8 my %ri = ( cc => 0, co => 1, re => 2, sr => 3, ci => 8, '' => 9 );
502 8 foreach (@args) {
503 # allow regular expressions optionally prefixed by "ci", "cc", "co", "re" or "sr"
504 24 ▶ if (m{^(-)?(\w{2})?/(.*)/(i?)$}) {
Branch: 6 branches
BranchTrueFalseTotal
if (m[^(-)?(\w{2})?/(.*)/(i?)$]) { } 1 23 24
elsif (/^[-+]?\d+(\.\d+)?$/) { } 12 11 23
elsif (/^([-+]?\d+(?:\.\d+)?) *(([NS])[A-Z]*)? +([-+]?\d+(?:\.\d+)?) *(([EW])[A-Z]*)?/i) { } 0 11 11
elsif (lc $_ eq 'both') { } 7 4 11
elsif ($_ =~ /^num=(\d+)$/i) { } 1 3 4
elsif ($_) { } 3 0 3
505 1 ▶ my $re = $4 ? qr/$3/im : qr/$3/m;
Branch: 1 branch
BranchTrueFalseTotal
$4 ? : 0 1 1
506 1 ▶ next if not defined($idx = $ri{$2});
Branch: 1 branch
BranchTrueFalseTotal
unless defined($idx = $ri{$2}) 0 1 1
507 1 push @cargs, $_;
508 1 ▶ $other = 1 if $idx < 5;
Branch: 1 branch
BranchTrueFalseTotal
if $idx < 5 1 0 1
509 1 ▶ $idx += 10 if $1; # add 10 for negative matches
Branch: 1 branch
BranchTrueFalseTotal
if $1 0 1 1
510 1 ▶ $regex{$idx} or $regex{$idx} = [ ];
Branch: 1 branch
BranchTrueFalseTotal
$regex{$idx} or $regex{$idx} = [] 0 1 1
511 1 push @{$regex{$idx}}, $re;
512 1 ▶ $city = '' unless defined $city;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $city 1 0 1
513 } elsif (/^[-+]?\d+(\.\d+)?$/) { # coordinate format
514 12 ▶ push @coords, $_ if @coords < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @coords < 2 12 0 12
515 } elsif (/^([-+]?\d+(?:\.\d+)?) *(([NS])[A-Z]*)? +([-+]?\d+(?:\.\d+)?) *(([EW])[A-Z]*)?/i) { # "lat lon" format
516 0 ▶ next if @coords;
Branch: 1 branch
BranchTrueFalseTotal
if @coords 0 0 0
517 0 my ($lat, $lon) = ($1, $4);
518 0 ▶ $lat = -abs($lat) if $3 and uc($3) eq 'S';
Branch: 1 branch
BranchTrueFalseTotal
if $3 and uc $3 eq "S" 0 0 0
Condition0%0/3
$3 and uc $3 eq "S"
!ll&&!rl&&r
000
MC/DC0%0/2
$3 and uc $3 eq "S"
$3 uc $3 eq "S"
Truth table0%0/3
A and B
A= $3B= uc $3 eq "S"
ABresult
0X0
100
111
519 0 ▶ $lon = -abs($lon) if $6 and uc($6) eq 'W';
Branch: 1 branch
BranchTrueFalseTotal
if $6 and uc $6 eq "W" 0 0 0
Condition0%0/3
$6 and uc $6 eq "W"
!ll&&!rl&&r
000
MC/DC0%0/2
$6 and uc $6 eq "W"
$6 uc $6 eq "W"
Truth table0%0/3
A and B
A= $6B= uc $6 eq "W"
ABresult
0X0
100
111
520 0 push @coords, $lat, $lon;
521 } elsif (lc $_ eq 'both') {
522 7 $both = 1;
523 } elsif ($_ =~ /^num=(\d+)$/i) {
524 1 $num = $1;
525 } elsif ($_) {
526 3 push @cargs, $_;
527 3 ▶ if ($city) {
Branch: 1 branch
BranchTrueFalseTotal
if ($city) { } 1 2 3
528 1 push @exact, lc $_;
529 } else {
530 2 $city = lc $_;
531 }
532 }
533 }
534 8 ▶ unless (defined $city or @coords == 2) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $city or @coords == 2) 0 8 8
Condition66%2/3
defined $city or @coords == 2
l!l&&r!l&&!r
350
MC/DC0%0/2
defined $city or @coords == 2
defined $city @coords == 2
Truth table66%2/3
A or B
A= defined $cityB= @coords == 2
ABresult
1X1
011
000
535 0 warn("Insufficient information to determine geolocation\n");
536 0 return();
537 }
538 # sort database by logitude if finding entry based on coordinates
539 8 ▶ SortDatabase('Latitude') if @coords == 2 and ($both or not defined $city);
Branch: 1 branch
BranchTrueFalseTotal
if @coords == 2 and $both || !defined($city) 6 2 8
Condition66%4/6
@coords == 2 and $both || !defined($city)
!ll&&!rl&&r
206
$both or not defined $city
l!l&&r!l&&!r
510
MC/DC33%1/3
@coords == 2 and $both || !defined($city)
@coords == 2 $both not defined $city
Truth table75%3/4
A and B or not(C)
A= @coords == 2B= $bothC= not defined $city
ABCresult
0XX0
1000
11X1
1011
540 #
541 # perform reverse Geolocation lookup to determine GPS based on city, country, etc.
542 #
543 8 ▶ while (defined $city and (@coords != 2 or $both)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $city and @coords != 2 || $both) 3 5 8
Condition66%4/6
defined $city and @coords != 2 || $both
!ll&&!rl&&r
503
@coords != 2 or $both
l!l&&r!l&&!r
210
MC/DC33%1/3
defined $city and @coords != 2 || $both
defined $city @coords != 2 $both
Truth table75%3/4
A and B or C
A= defined $cityB= @coords != 2C= $both
ABCresult
0XX0
1000
11X1
1011
544 3 ▶ my $cargs = join(',', @cargs, $pop||'', $maxDist||'', $fcodes||'');
Condition50%3/6
$pop || ''
l!l
03
$maxDist || ''
l!l
03
$fcodes || ''
l!l
03
MC/DC0%0/1
$pop || ''
$pop
MC/DC0%0/1
$maxDist || ''
$maxDist
MC/DC0%0/1
$fcodes || ''
$fcodes
Truth table50%1/2
A
A= $pop
Aresult
11
00
Truth table50%1/2
A
A= $maxDist
Aresult
11
00
Truth table50%1/2
A
A= $fcodes
Aresult
11
00
545 3 my $i = 0;
546 3 ▶ if ($lastArgs and $lastArgs eq $cargs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lastArgs and $lastArgs eq $cargs) { } 0 3 3
Condition66%2/3
$lastArgs and $lastArgs eq $cargs
!ll&&!rl&&r
210
MC/DC0%0/2
$lastArgs and $lastArgs eq $cargs
$lastArgs $lastArgs eq $cargs
Truth table66%2/3
A and B
A= $lastArgsB= $lastArgs eq $cargs
ABresult
0X0
100
111
547 0 $i = @cityList; # bypass search
548 } else {
549 3 ClearLastMatches();
550 3 $lastArgs = $cargs;
551 }
552 # read alternate names database if an exact city match is specified
553 3 ▶ if ($altNames) {
Branch: 1 branch
BranchTrueFalseTotal
if ($altNames) { } 3 0 3
554 3 ▶ ReadAltNames() if $city and $altDir;
Branch: 1 branch
BranchTrueFalseTotal
if $city and $Image::ExifTool::Geolocation::altDir 0 3 3
Condition66%2/3
$city and $Image::ExifTool::Geolocation::altDir
!ll&&!rl&&r
120
MC/DC0%0/2
$city and $Image::ExifTool::Geolocation::altDir
$city $Image::ExifTool::Geolocation::altDir
Truth table66%2/3
A and B
A= $cityB= $Image::ExifTool::Geolocation::altDir
ABresult
0X0
100
111
555 3 $altNames = \@altNames;
556 } else {
557 0 $altNames = [ ]; # (don't search alt names)
558 }
559 3 ▶Entry: for (; $i<@cityList; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @cityList) 348164 3 348167
560 348164 my $cty = substr($cityList[$i],13);
561 348164 ▶ if ($city and $city ne lc $cty) { # test exact city name first
Branch: 1 branch
BranchTrueFalseTotal
if ($city and $city ne lc $cty) 232095 116069 348164
Condition100%3/3
$city and $city ne lc $cty
!ll&&!rl&&r
11605514232095
MC/DC100%2/2
$city and $city ne lc $cty
$city $city ne lc $cty
Truth table100%3/3
A and B
A= $cityB= $city ne lc $cty
ABresult
0X0
100
111
562 232095 ▶ next unless $$altNames[$i] and $$altNames[$i] =~ /^$city$/im;
Branch: 1 branch
BranchTrueFalseTotal
unless $altNames->[$i] and $altNames->[$i] =~ /^$city$/im 232094 1 232095
Condition66%2/3
$altNames->[$i] and $altNames->[$i] =~ /^$city$/im
!ll&&!rl&&r
23209401
MC/DC50%1/2
$altNames->[$i] and $altNames->[$i] =~ /^$city$/im
$altNames->[$i] $altNames->[$i] =~ /^$city$/im
Truth table66%2/3
A and B
A= $altNames->[$i]B= $altNames->[$i] =~ /^$city$/im
ABresult
0X0
100
111
563 }
564 # test with city-specific regexes
565 0 ▶ if ($regex{8}) { $cty =~ $_ or next Entry foreach @{$regex{8}} }
Branch: 2 branches
BranchTrueFalseTotal
if ($regex{8}) 0 116070 116070
$cty =~ /$_/ or next Entry 0 0 0
566 0 ▶ if ($regex{18}) { $cty !~ $_ or next Entry foreach @{$regex{18}} }
Branch: 2 branches
BranchTrueFalseTotal
if ($regex{18}) 0 116070 116070
$cty =~ /$_/ and next Entry 0 0 0
567 # test other arguments
568 116070 my ($cd,$sn) = unpack('x5Nn', $cityList[$i]);
569 116070 my $ct = $countryList[$cd >> 24];
570 116070 ▶ $sn &= 0x7fff if $dbVer eq '1.02';
Branch: 1 branch
BranchTrueFalseTotal
if $dbVer eq "1.02" 0 116070 116070
571 116070 my @geo = (substr($ct,0,2), substr($ct,2), $regionList[$cd & 0x0fff], $subregionList[$sn]);
572 116070 ▶ if (@exact) {
Branch: 1 branch
BranchTrueFalseTotal
if (@exact) 14 116056 116070
573 # make quick lookup for all names at this location
574 14 my %geoLkup;
575 14 ▶ $_ and $geoLkup{lc $_} = 1 foreach @geo;
Branch: 1 branch
BranchTrueFalseTotal
$_ and $geoLkup{lc $_} = 1 54 2 56
576 14 ▶ $geoLkup{$_} or next Entry foreach @exact;
Branch: 1 branch
BranchTrueFalseTotal
$geoLkup{$_} or next Entry 1 13 14
577 }
578 # test with cc, co, re and sr regexes
579 116057 ▶ if ($other) { foreach $idx (0..3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($other) 116055 2 116057
580 236318 ▶ if ($regex{$idx}) { $geo[$idx] =~ $_ or next Entry foreach @{$regex{$idx}} }
Branch: 2 branches
BranchTrueFalseTotal
if ($regex{$idx}) 116055 120263 236318
$geo[$idx] =~ /$_/m or next Entry 2104 113951 116055
581 0 ▶ if ($regex{$idx+10}) { $geo[$idx] !~ $_ or next Entry foreach @{$regex{$idx+10}} }
Branch: 2 branches
BranchTrueFalseTotal
if ($regex{$idx + 10}) 0 122367 122367
$geo[$idx] =~ /$_/ and next Entry 0 0 0
582 } }
583 # test regexes for any place name
584 2106 ▶ if ($regex{9} or $regex{19}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($regex{9} or $regex{19}) 0 2106 2106
Condition33%1/3
$regex{9} or $regex{19}
l!l&&r!l&&!r
002106
MC/DC0%0/2
$regex{9} or $regex{19}
$regex{9} $regex{19}
Truth table33%1/3
A or B
A= $regex{9}B= $regex{19}
ABresult
1X1
011
000
585 0 my $str = join "\n", $cty, @geo;
586 0 ▶ $str =~ $_ or next Entry foreach @{$regex{9}};
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /$_/ or next Entry 0 0 0
587 0 ▶ $str !~ $_ or next Entry foreach @{$regex{19}};
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /$_/ and next Entry 0 0 0
588 }
589 # test feature code and population
590 2106 ▶ next if $fcodes and not $fcOK{ord(substr($cityList[$i],12,1)) & 0x3f};
Branch: 1 branch
BranchTrueFalseTotal
if $fcodes and not $fcOK{ord substr($cityList[$i], 12, 1) & 63} 0 2106 2106
Condition33%1/3
$fcodes and not $fcOK{ord substr($cityList[$i], 12, 1) & 63}
!ll&&!rl&&r
210600
MC/DC0%0/2
$fcodes and not $fcOK{ord substr($cityList[$i], 12, 1) & 63}
$fcodes not $fcOK{ord substr($cityList[$i], 12, 1) & 63}
Truth table33%1/3
A and not(B)
A= $fcodesB= not $fcOK{ord substr($cityList[$i], 12, 1) & 63}
ABresult
0X0
100
111
591 2106 my $pc = substr($cityList[$i],6,2);
592 2106 ▶ if (not defined $minPop or $pc ge $minPop) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $minPop or $pc ge $minPop) 2106 0 2106
Condition33%1/3
not defined $minPop or $pc ge $minPop
l!l&&r!l&&!r
210600
MC/DC0%0/2
not defined $minPop or $pc ge $minPop
not defined $minPop $pc ge $minPop
Truth table33%1/3
not(A) or B
A= not defined $minPopB= $pc ge $minPop
ABresult
1X1
011
000
593 2106 $lastFound{$i} = $pc;
594 2106 ▶ push @lastByLat, $i if @coords == 2;
Branch: 1 branch
BranchTrueFalseTotal
if @coords == 2 2104 2 2106
595 }
596 }
597 3 ▶ @startTime and printf("= Processing time: %.3f sec\n", Time::HiRes::tv_interval(\@startTime));
Branch: 1 branch
BranchTrueFalseTotal
@startTime and printf "= Processing time: %.3f sec\n", Time::HiRes::tv_interval(\@startTime) 0 3 3
598 3 ▶ if (%lastFound) {
Branch: 1 branch
BranchTrueFalseTotal
if (%lastFound) 3 0 3
599 3 ▶ last if @coords == 2; # continue to use coords with last city matches
Branch: 1 branch
BranchTrueFalseTotal
if @coords == 2 1 2 3
600 2 ▶ scalar(keys %lastFound) > 200 and warn("Too many matching cities\n"), return();
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %lastFound > 200 and warn("Too many matching cities\n"), (return ()) 0 2 2
601 # return nearby cities if "num=" is used and only one match found
602 2 ▶ if ($num > 1 and scalar(keys %lastFound) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num > 1 and scalar keys %lastFound == 1) 0 2 2
Condition33%1/3
$num > 1 and scalar keys %lastFound == 1
!ll&&!rl&&r
200
MC/DC0%0/2
$num > 1 and scalar keys %lastFound == 1
$num > 1 scalar keys %lastFound == 1
Truth table33%1/3
A and B
A= $num > 1B= scalar keys %lastFound == 1
ABresult
0X0
100
111
603 0 my ($i) = keys %lastFound;
604 0 my @entry = GetEntry($i);
605 0 @coords = @entry[8,9];
606 0 SortDatabase('Latitude'); # (make sure we are sorted by latitude)
607 0 last;
608 }
609 2 ▶ unless (@lastByPop) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@lastByPop) 2 0 2
610 0 ▶ @lastByPop = sort { $lastFound{$b} cmp $lastFound{$a} or $cityList[$a] cmp $cityList[$b] } keys %lastFound;
Condition0%0/3
$lastFound{$b} cmp $lastFound{$a} || $cityList[$a] cmp $cityList[$b]
l!l&&r!l&&!r
000
MC/DC0%0/2
$lastFound{$b} cmp $lastFound{$a} || $cityList[$a] cmp $cityList[$b]
$lastFound{$b} cmp $lastFound{$a} $cityList[$a] cmp $cityList[$b]
Truth table0%0/3
A || B
A= $lastFound{$b} cmp $lastFound{$a}B= $cityList[$a] cmp $cityList[$b]
ABresult
1X1
011
000
611 }
612 2 return(\@lastByPop);
613 }
614 0 warn "No such city in Geolocation database\n";
615 0 return();
616 }
617 #
618 # determine Geolocation based on GPS coordinates
619 #
620 6 my ($lat, $lon) = @coords;
621 6 ▶ if ($maxDist) {
Branch: 1 branch
BranchTrueFalseTotal
if ($maxDist) { } 0 6 6
622 0 $minDistU = $maxDist / (2 * $earthRadius); # min distance on unit sphere
623 0 $minDistC = $maxDist * 0x100000 / ($pi * $earthRadius); # min distance in coordinate units
624 } else {
625 6 $minDistU = $pi;
626 6 $minDistC = 0x200000;
627 }
628 6 my $cos = cos($lat * $pi / 180); # cosine factor for longitude distances
629 # reduce lat/lon to the range 0-0x100000
630 6 $lat = int(($lat + 90) / 180 * 0x100000 + 0.5) & 0xfffff;
631 6 $lon = int(($lon + 180) / 360 * 0x100000 + 0.5) & 0xfffff;
632 6 ▶ $lat or $lat = $coords[0] < 0 ? 1 : 0xfffff; # (zero latitude is a problem for our calculations)
Branch: 2 branches
BranchTrueFalseTotal
$lat or $lat = $coords[0] < 0 ? 1 : 1048575 6 0 6
$coords[0] < 0 ? : 0 0 0
633 6 my $coord = pack('nCn',$lat>>4,(($lat&0x0f)<<4)|($lon&0x0f),$lon>>4);;
634 # start from cached city matches if also using city information
635 6 ▶ my $numEntries = @lastByLat || @cityList;
Condition66%2/3
@lastByLat || @cityList
l!l&&r!l&&!r
150
MC/DC0%0/2
@lastByLat || @cityList
@lastByLat @cityList
Truth table66%2/3
A || B
A= @lastByLatB= @cityList
ABresult
1X1
011
000
636 # binary search to find closest longitude
637 6 my ($n0, $n1) = (0, $numEntries - 1);
638 6 ▶ my $sorted = @lastByLat ? \@lastByLat : (@sortOrder ? \@sortOrder : undef);
Branch: 2 branches
BranchTrueFalseTotal
@lastByLat ? : 1 5 6
@sortOrder ? : 0 5 5
639 6 ▶ while ($n1 - $n0 > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n1 - $n0 > 1) 96 6 102
640 96 my $n = int(($n0 + $n1) / 2);
641 96 ▶ if ($coord lt $cityList[$sorted ? $$sorted[$n] : $n]) {
Branch: 2 branches
BranchTrueFalseTotal
if ($coord lt $cityList[$sorted ? $sorted->[$n] : $n]) { } 46 50 96
$sorted ? : 11 85 96
642 46 $n1 = $n;
643 } else {
644 50 $n0 = $n;
645 }
646 }
647 # step backward then forward through database to find nearest city
648 6 my ($inc, $end, $n) = (-1, -1, $n0+1);
649 6 my ($p0, $t0) = ($lat*$pi/0x100000 - $pi/2, $lon*$pi/0x080000 - $pi);
650 6 my $cp0 = cos($p0);
651 6 my (@matches, @rtnList, @dist);
652  
653 6 for (;;) {
654 42413 ▶ if (($n += $inc) == $end) {
Branch: 1 branch
BranchTrueFalseTotal
if (($n += $inc) == $end) 12 42401 42413
655 12 ▶ last if $inc == 1 or $n0 == $n1;
Branch: 1 branch
BranchTrueFalseTotal
if $inc == 1 or $n0 == $n1 6 6 12
Condition66%2/3
$inc == 1 or $n0 == $n1
l!l&&r!l&&!r
606
MC/DC50%1/2
$inc == 1 or $n0 == $n1
$inc == 1 $n0 == $n1
Truth table66%2/3
A or B
A= $inc == 1B= $n0 == $n1
ABresult
1X1
011
000
656 6 ($inc, $end, $n) = (1, $numEntries, $n1);
657 }
658 42407 ▶ my $i = $sorted ? $$sorted[$n] : $n;
Branch: 1 branch
BranchTrueFalseTotal
$sorted ? : 2103 40304 42407
659 # get city latitude/longitude
660 42407 my ($lt,$f,$ln) = unpack('nCn', $cityList[$i]);
661 42407 $lt = ($lt << 4) | ($f >> 4);
662 # searched far enough if latitude alone is further than best distance
663 42407 ▶ abs($lt - $lat) > $minDistC and $n = $end - $inc, next;
Branch: 1 branch
BranchTrueFalseTotal
abs $lt - $lat > $minDistC and $n = $end - $inc, next 11 42396 42407
664 # ignore if population is below threshold
665 42396 ▶ next if defined $minPop and $minPop ge substr($cityList[$i],6,2);
Branch: 1 branch
BranchTrueFalseTotal
if defined $minPop and $minPop ge substr($cityList[$i], 6, 2) 38784 3612 42396
Condition100%3/3
defined $minPop and $minPop ge substr($cityList[$i], 6, 2)
!ll&&!rl&&r
349411838784
MC/DC100%2/2
defined $minPop and $minPop ge substr($cityList[$i], 6, 2)
defined $minPop $minPop ge substr($cityList[$i], 6, 2)
Truth table100%3/3
A and B
A= defined $minPopB= $minPop ge substr($cityList[$i], 6, 2)
ABresult
0X0
100
111
666 3612 ▶ next if $fcodes and not $fcOK{ord(substr($cityList[$i],12,1)) & 0x3f};
Branch: 1 branch
BranchTrueFalseTotal
if $fcodes and not $fcOK{ord substr($cityList[$i], 12, 1) & 63} 31 3581 3612
Condition100%3/3
$fcodes and not $fcOK{ord substr($cityList[$i], 12, 1) & 63}
!ll&&!rl&&r
295862331
MC/DC100%2/2
$fcodes and not $fcOK{ord substr($cityList[$i], 12, 1) & 63}
$fcodes not $fcOK{ord substr($cityList[$i], 12, 1) & 63}
Truth table100%3/3
A and not(B)
A= $fcodesB= not $fcOK{ord substr($cityList[$i], 12, 1) & 63}
ABresult
0X0
100
111
667 3581 $ln = ($ln << 4) | ($f & 0x0f);
668 # calculate great circle distance to this city on unit sphere
669 3581 my ($p1, $t1) = ($lt*$pi/0x100000 - $pi/2, $ln*$pi/0x080000 - $pi);
670 3581 my ($sp, $st) = (sin(($p1-$p0)/2), sin(($t1-$t0)/2));
671 3581 my $a = $sp * $sp + $cp0 * cos($p1) * $st * $st;
672 3581 my $distU = atan2(sqrt($a), sqrt(1-$a)); # distance on unit sphere
673 3581 ▶ next if $distU > $minDistU;
Branch: 1 branch
BranchTrueFalseTotal
if $distU > $minDistU 3516 65 3581
674 65 @matchParms = ($i, $p1, $t1, $distU);
675 65 ▶ if ($num <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num <= 1) { } 51 14 65
676 51 $minDistU = $distU;
677 } else {
678 14 my $j;
679 # add this entry into list of matching cities ordered by closest first
680 14 ▶ for ($j=0; $j<@matches; ++$j) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < @matches) 19 2 21
681 19 ▶ last if $distU < $matches[$j][3];
Branch: 1 branch
BranchTrueFalseTotal
if $distU < $matches[$j][3] 12 7 19
682 }
683 14 ▶ if ($j < $#matches) {
Branch: 1 branch
BranchTrueFalseTotal
if ($j < $#matches) { } 6 8 14
684 6 splice @matches, $j, 0, [ @matchParms ];
685 } else {
686 8 $matches[$j] = [ @matchParms ];
687 }
688 # restrict list to the specified number of nearest cities
689 14 ▶ pop @matches if @matches > $num;
Branch: 1 branch
BranchTrueFalseTotal
if @matches > $num 6 8 14
690 # update minimum distance with furthest match if we satisfied our quota
691 14 ▶ $minDistU = $matches[-1][3] if @matches >= $num;
Branch: 1 branch
BranchTrueFalseTotal
if @matches >= $num 13 1 14
692 }
693 65 $minDistC = $minDistU * 0x200000 / $pi; # distance in scaled coordinate units
694 }
695 6 ▶ @matchParms or warn("No suitable location in Geolocation database\n"), return();
Branch: 1 branch
BranchTrueFalseTotal
@matchParms or warn("No suitable location in Geolocation database\n"), (return ()) 6 0 6
696 6 $num = @matches;
697  
698 6 ▶ @startTime and printf("- Processing time: %.3f sec\n", Time::HiRes::tv_interval(\@startTime));
Branch: 1 branch
BranchTrueFalseTotal
@startTime and printf "- Processing time: %.3f sec\n", Time::HiRes::tv_interval(\@startTime) 0 6 6
699  
700 6 for (;;) {
701 8 ▶ if ($num > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($num > 1) 3 5 8
702 3 ▶ last unless @matches;
Branch: 1 branch
BranchTrueFalseTotal
unless @matches 1 2 3
703 2 @matchParms = @{$matches[0]};
704 2 shift @matches;
705 }
706 # calculate distance in km and bearing to matching city
707 7 my ($ii, $p1, $t1, $distU) = @matchParms;
708 7 my $km = sprintf('%.2f', 2 * $earthRadius * $distU);
709 7 my $be = atan2(sin($t1-$t0)*cos($p1-$p0), $cp0*sin($p1)-sin($p0)*cos($p1)*cos($t1-$t0));
710 7 $be = int($be * 180 / $pi + 360.5) % 360; # convert from radians to integer degrees
711 7 push @rtnList, $ii;
712 7 push @dist, [ $km, $be ];
713 7 ▶ last if $num <= 1;
Branch: 1 branch
BranchTrueFalseTotal
if $num <= 1 5 2 7
714 }
715 6 ▶ return wantarray ? (\@rtnList, \@dist) : \@rtnList;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 6 0 6
716 }
717  
718 1 1; #end
719  
720 __END__
« Image/ExifTool/IPTC.pm ↑ Summary Image/ExifTool/Text.pm »