Image/ExifTool/Import.pm

filter: Statementstmt 57.3% 101 / 176 Branchbran 36.9% 54 / 146 Conditioncond 25.7% 9 / 35 MC/DCmcdc 14.2% 3 / 21 Subroutinesub 66.6% 4 / 6 Podpod 50.0% 2 / 4 totaltotal 44.5% 173 / 388 CC 89 SCAR 62.2
CC
89
Cov
46%
ReadCSV
1260.0
ReadJSONObject
64.2
ReadJSON
35.9
CRAP 502.3
« Image/ExifTool/Photoshop.pm ↑ Summary Image/ExifTool/WritePDF.pl »
1 #------------------------------------------------------------------------------
2 # File: Import.pm
3 #
4 # Description: Import CSV and JSON database files
5 #
6 # Revisions: 2011-03-05 - P. Harvey Created
7 #------------------------------------------------------------------------------
8 package Image::ExifTool::Import;
9  
10 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 17 require Exporter;
12  
13 17 ▶use vars qw($VERSION @ISA @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 17 $VERSION = '1.14';
16 17 @ISA = qw(Exporter);
17 17 @EXPORT_OK = qw(ReadCSV ReadJSON);
18  
19 sub ReadJSONObject($;$);
20  
21 17 my %unescapeJSON = ( 't'=>"\t", 'n'=>"\n", 'r'=>"\r", 'b' => "\b", 'f' => "\f" );
22 17 my $charset;
23  
24 #------------------------------------------------------------------------------
25 # Read CSV file
26 # Inputs: 0) CSV file name, file ref or RAF ref, 1) database hash ref,
27 # 2) missing tag value, 3) delimiter if other than ','
28 # Returns: undef on success, or error string
29 # Notes: There are various flavours of CSV, but here we assume that only
30 # double quotes are escaped, and they are escaped by doubling them
31 sub ReadCSV($$;$$)
32 0 ▶{
Subroutine ReadCSV: not called CC=35 SCAR=71.4
Pod documented
33 0 local ($_, $/);
34 0 my ($file, $database, $missingValue, $delim) = @_;
35 0 my ($buff, @tags, $found, $err, $raf, $openedFile);
36  
37 0 ▶ if (UNIVERSAL::isa($file, 'File::RandomAccess')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($file, 'File::RandomAccess')) { } 0 0 0
elsif (ref $file eq 'GLOB') { } 0 0 0
38 0 $raf = $file;
39 0 $file = 'CSV file';
40 } elsif (ref $file eq 'GLOB') {
41 0 $raf = File::RandomAccess->new($file);
42 0 $file = 'CSV file';
43 } else {
44 0 ▶ open CSVFILE, $file or return "Error opening CSV file '${file}'";
Branch: 1 branch
BranchTrueFalseTotal
open CSVFILE, $file or return "Error opening CSV file '${file}'" 0 0 0
45 0 binmode CSVFILE;
46 0 $openedFile = 1;
47 0 $raf = File::RandomAccess->new(\*CSVFILE);
48 }
49 0 ▶ $delim = ',' unless defined $delim;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $delim 0 0 0
50 # set input record separator by first newline found in the file
51 # (safe because first line should contain only tag names)
52 0 ▶ while ($raf->Read($buff, 65536)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf->Read($buff, 65536)) 0 0 0
53 0 ▶ $buff =~ /(\x0d\x0a|\x0d|\x0a)/ and $/ = $1, last;
Branch: 1 branch
BranchTrueFalseTotal
$buff =~ /(\x0d\x0a|\x0d|\x0a)/ and $/ = $1, last 0 0 0
54 }
55 0 $raf->Seek(0,0);
56 0 ▶ while ($raf->ReadLine($buff)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($raf->ReadLine($buff)) 0 0 0
57 0 my (@vals, $v, $i, %fileInfo);
58 0 my @toks = split /\Q$delim/, $buff;
59 0 ▶ while (@toks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@toks) 0 0 0
60 0 ($v = shift @toks) =~ s/^ +//; # remove leading spaces
61 0 ▶ if ($v =~ s/^"//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v =~ s/^"//) { } 0 0 0
62 # quoted value must end in an odd number of quotes
63 0 ▶ while ($v !~ /("+)\s*$/ or not length($1) & 1) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v =~ /("+)\s*$/ and length $1 & 1) 0 0 0
Condition0%0/3
$v =~ /("+)\s*$/ and length $1 & 1
!ll&&!rl&&r
000
MC/DC0%0/2
$v =~ /("+)\s*$/ and length $1 & 1
$v =~ /("+)\s*$/ length $1 & 1
Truth table0%0/3
A and B
A= $v =~ /("+)\s*$/B= length $1 & 1
ABresult
0X0
100
111
64 0 ▶ if (@toks) {
Branch: 1 branch
BranchTrueFalseTotal
if (@toks) { } 0 0 0
65 0 $v .= $delim . shift @toks;
66 } else {
67 # read another line from the file
68 0 ▶ $raf->ReadLine($buff) or last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->ReadLine($buff) or last 0 0 0
69 0 @toks = split /\Q$delim/, $buff;
70 0 ▶ last unless @toks;
Branch: 1 branch
BranchTrueFalseTotal
unless @toks 0 0 0
71 0 $v .= shift @toks;
72 }
73 }
74 0 $v =~ s/"\s*$//; # remove trailing quote and whitespace
75 0 $v =~ s/""/"/g; # un-escape quotes
76 } else {
77 0 $v =~ s/[ \n\r]+$//;# remove trailing spaces/newlines
78 }
79 0 push @vals, $v;
80 }
81 0 ▶ if (@tags) {
Branch: 1 branch
BranchTrueFalseTotal
if (@tags) { } 0 0 0
82 # save values for each tag
83 0 $fileInfo{_ordered_keys_} = [ ];
84 0 ▶ for ($i=0; $i<@vals and $i<@tags; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @vals and $i < @tags) 0 0 0
Condition0%0/3
$i < @vals and $i < @tags
!ll&&!rl&&r
000
MC/DC0%0/2
$i < @vals and $i < @tags
$i < @vals $i < @tags
Truth table0%0/3
A and B
A= $i < @valsB= $i < @tags
ABresult
0X0
100
111
85 # ignore empty entries unless missingValue is empty too
86 0 ▶ next unless length $vals[$i] or defined $missingValue and $missingValue eq '';
Branch: 1 branch
BranchTrueFalseTotal
unless length $vals[$i] or defined $missingValue and $missingValue eq "" 0 0 0
Condition0%0/6
length $vals[$i] or defined $missingValue and $missingValue eq ""
l!l&&r!l&&!r
000
defined $missingValue and $missingValue eq ""
!ll&&!rl&&r
000
MC/DC0%0/3
length $vals[$i] or defined $missingValue and $missingValue eq ""
length $vals[$i] defined $missingValue $missingValue eq ""
Truth table0%0/4
A or B and C
A= length $vals[$i]B= defined $missingValueC= $missingValue eq ""
ABCresult
1XX1
0111
00X0
0100
87 # delete tag (set value to undef) if value is same as missing tag
88 0 ▶ $fileInfo{$tags[$i]} =
Branch: 1 branch
BranchTrueFalseTotal
defined $missingValue && $vals[$i] eq $missingValue ? : 0 0 0
Condition0%0/3
defined $missingValue and $vals[$i] eq $missingValue
!ll&&!rl&&r
000
MC/DC0%0/2
defined $missingValue and $vals[$i] eq $missingValue
defined $missingValue $vals[$i] eq $missingValue
Truth table0%0/3
A and B
A= defined $missingValueB= $vals[$i] eq $missingValue
ABresult
0X0
100
111
89 (defined $missingValue and $vals[$i] eq $missingValue) ? undef : $vals[$i];
90 0 push @{$fileInfo{_ordered_keys_}}, $tags[$i];
91 }
92 # figure out the file name to use
93 0 ▶ if ($fileInfo{SourceFile}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fileInfo{"SourceFile"}) 0 0 0
94 0 $$database{$fileInfo{SourceFile}} = \%fileInfo;
95 0 $found = 1;
96 }
97 } else {
98 # the first row should be the tag names
99 0 foreach (@vals) {
100 # terminate at first blank tag name (eg. extra comma at end of line)
101 0 ▶ last unless length $_;
Branch: 1 branch
BranchTrueFalseTotal
unless length $_ 0 0 0
102 0 ▶ @tags or s/^\xef\xbb\xbf//; # remove UTF-8 BOM if it exists
Branch: 1 branch
BranchTrueFalseTotal
@tags or s/^\xef\xbb\xbf// 0 0 0
103 0 ▶ /^([-_0-9A-Z]+:)*[-_0-9A-Z]+#?$/i or $err = "Invalid tag name '${_}'", last;
Branch: 1 branch
BranchTrueFalseTotal
/^([-_0-9A-Z]+:)*[-_0-9A-Z]+#?$/i or $err = "Invalid tag name '${_}'", last 0 0 0
104 0 push(@tags, $_);
105 }
106 0 ▶ last if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 0 0 0
107 0 ▶ @tags or $err = 'No tags found', last;
Branch: 1 branch
BranchTrueFalseTotal
@tags or $err = "No tags found", last 0 0 0
108 # fix "SourceFile" case if necessary
109 0 ▶ $tags[0] = 'SourceFile' if lc $tags[0] eq 'sourcefile';
Branch: 1 branch
BranchTrueFalseTotal
if lc $tags[0] eq "sourcefile" 0 0 0
110 }
111 }
112 0 ▶ close CSVFILE if $openedFile;
Branch: 1 branch
BranchTrueFalseTotal
if $openedFile 0 0 0
113 0 undef $raf;
114 0 ▶ $err = 'No SourceFile column' unless $found or $err;
Branch: 1 branch
BranchTrueFalseTotal
unless $found or $err 0 0 0
Condition0%0/3
$found or $err
l!l&&r!l&&!r
000
MC/DC0%0/2
$found or $err
$found $err
Truth table0%0/3
A or B
A= $foundB= $err
ABresult
1X1
011
000
115 0 ▶ return $err ? "$err in $file" : undef;
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 0 0
116 }
117  
118 #------------------------------------------------------------------------------
119 # Convert unicode code point to UTF-8
120 # Inputs: 0) integer Unicode character
121 # Returns: UTF-8 bytes
122 sub ToUTF8($)
123 0 ▶{
Subroutine ToUTF8: not called CC=1 SCAR=6.9
Pod undocumented
124 0 require Image::ExifTool::Charset;
125 0 return Image::ExifTool::Charset::Recompose(undef, [$_[0]], $charset);
126 }
127  
128 #------------------------------------------------------------------------------
129 # Read JSON object from file
130 # Inputs: 0) RAF reference or undef, 1) optional scalar reference for data
131 # to read before reading from file (ie. the file read buffer)
132 # Returns: JSON object (scalar, hash ref, or array ref), or undef on EOF or
133 # empty object or array (and sets $$buffPt to empty string on EOF)
134 # Notes: position in buffer is significant
135 sub ReadJSONObject($;$)
136 510 ▶{
Subroutine ReadJSONObject: called CC=39 SCAR=41.6
Pod undocumented
137 510 my ($raf, $buffPt) = @_;
138 # initialize buffer if necessary
139 510 my ($pos, $readMore, $rtnVal, $tok, $key, $didBOM);
140 510 ▶ if ($buffPt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buffPt) { } 449 61 510
141 449 $pos = pos $$buffPt;
142 449 ▶ $pos = pos($$buffPt) = 0 unless defined $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 449 449
143 } else {
144 61 my $buff = '';
145 61 $buffPt = \$buff;
146 61 $pos = 0;
147 }
148 510 Tok: for (;;) {
149 # (didn't spend the time to understand how $pos could be undef, but
150 # put a test here to be safe because one user reported this problem)
151 510 ▶ last unless defined $pos;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos 0 510 510
152 510 ▶ if ($pos >= length $$buffPt or $readMore) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= length $$buffPt or $readMore) 61 449 510
Condition66%2/3
$pos >= length $$buffPt or $readMore
l!l&&r!l&&!r
610449
MC/DC50%1/2
$pos >= length $$buffPt or $readMore
$pos >= length $$buffPt $readMore
Truth table66%2/3
A or B
A= $pos >= length $$buffPtB= $readMore
ABresult
1X1
011
000
153 61 ▶ last unless defined $raf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raf 0 61 61
154 # read another 64kB and add to unparsed data
155 61 my $offset = length($$buffPt) - $pos;
156 61 ▶ if ($offset) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset) { } 0 61 61
157 0 my $buff;
158 0 ▶ $raf->Read($buff, 65536) or $$buffPt = '', last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($buff, 65536) or $$buffPt = "", last 0 0 0
159 0 $$buffPt = substr($$buffPt, $pos) . $buff;
160 } else {
161 61 ▶ $raf->Read($$buffPt, 65536) or $$buffPt = '', last;
Branch: 1 branch
BranchTrueFalseTotal
$raf->Read($$buffPt, 65536) or $$buffPt = "", last 61 0 61
162 }
163 61 ▶ unless ($didBOM) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($didBOM) 61 0 61
164 61 $$buffPt =~ s/^\xef\xbb\xbf//; # remove UTF-8 BOM if it exists
165 61 $didBOM = 1;
166 }
167 61 $pos = pos($$buffPt) = 0;
168 61 $readMore = 0;
169 }
170 510 ▶ unless ($tok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tok) 510 0 510
171 # skip white space and find next character
172 510 ▶ $$buffPt =~ /(\S)/g or $pos = length($$buffPt), next;
Branch: 1 branch
BranchTrueFalseTotal
$$buffPt =~ /(\S)/g or $pos = length $$buffPt, next 510 0 510
173 510 $tok = $1;
174 510 $pos = pos $$buffPt;
175 }
176 # see what type of object this is
177 510 ▶ if ($tok eq '{') { # object (hash)
Branch: 4 branches
BranchTrueFalseTotal
if ($tok eq '{') { } 107 403 510
elsif ($tok eq '[') { } 17 386 403
elsif ($tok eq '"') { } 295 91 386
elsif ($tok eq ']' or $tok eq '}' or $tok eq ',') { } 8 83 91
178 107 ▶ $rtnVal = { _ordered_keys_ => [ ] } unless defined $rtnVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rtnVal 107 0 107
179 107 for (;;) {
180 # read "KEY":"VALUE" pairs
181 208 ▶ unless (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $key) 208 0 208
182 208 $key = ReadJSONObject($raf, $buffPt);
183 208 $pos = pos $$buffPt;
184 }
185 # ($key may be undef for empty JSON object)
186 208 ▶ if (defined $key) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 205 3 208
187 # scan to delimiting ':'
188 205 ▶ $$buffPt =~ /(\S)/g or $readMore = 1, next Tok;
Branch: 1 branch
BranchTrueFalseTotal
$$buffPt =~ /(\S)/g or $readMore = 1, next Tok 205 0 205
189 205 ▶ $1 eq ':' or return undef; # error if not a colon
Branch: 1 branch
BranchTrueFalseTotal
$1 eq ":" or return undef 205 0 205
190 205 my $val = ReadJSONObject($raf, $buffPt);
191 205 $pos = pos $$buffPt;
192 205 ▶ return undef unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 205 205
193 205 $$rtnVal{$key} = $val;
194 205 push @{$$rtnVal{_ordered_keys_}}, $key;
195 205 undef $key;
196 }
197 # scan to delimiting ',' or bounding '}'
198 208 ▶ $$buffPt =~ /(\S)/g or $readMore = 1, next Tok;
Branch: 1 branch
BranchTrueFalseTotal
$$buffPt =~ /(\S)/g or $readMore = 1, next Tok 208 0 208
199 208 ▶ last if $1 eq '}'; # check for end of object
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "}" 107 101 208
200 101 ▶ $1 eq ',' or return undef; # error if not a comma
Branch: 1 branch
BranchTrueFalseTotal
$1 eq "," or return undef 101 0 101
201 }
202 } elsif ($tok eq '[') { # array
203 17 ▶ $rtnVal = [ ] unless defined $rtnVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rtnVal 17 0 17
204 17 for (;;) {
205 33 my $item = ReadJSONObject($raf, $buffPt);
206 33 $pos = pos $$buffPt;
207 # ($item may be undef for empty array)
208 33 ▶ push @$rtnVal, $item if defined $item;
Branch: 1 branch
BranchTrueFalseTotal
if defined $item 28 5 33
209 # scan to delimiting ',' or bounding ']'
210 33 ▶ $$buffPt =~ /(\S)/g or $readMore = 1, next Tok;
Branch: 1 branch
BranchTrueFalseTotal
$$buffPt =~ /(\S)/g or $readMore = 1, next Tok 33 0 33
211 33 ▶ last if $1 eq ']'; # check for end of array
Branch: 1 branch
BranchTrueFalseTotal
if $1 eq "]" 17 16 33
212 16 ▶ $1 eq ',' or return undef; # error if not a comma
Branch: 1 branch
BranchTrueFalseTotal
$1 eq "," or return undef 16 0 16
213 }
214 } elsif ($tok eq '"') { # quoted string
215 295 for (;;) {
216 295 ▶ $$buffPt =~ /(\\*)"/g or $readMore = 1, next Tok;
Branch: 1 branch
BranchTrueFalseTotal
$$buffPt =~ /(\\*)"/g or $readMore = 1, next Tok 295 0 295
217 295 ▶ last unless length($1) & 1; # check for escaped quote
Branch: 1 branch
BranchTrueFalseTotal
unless length $1 & 1 295 0 295
218 }
219 295 $rtnVal = substr($$buffPt, $pos, pos($$buffPt)-$pos-1);
220 # unescape characters
221 0 $rtnVal =~ s/\\u([0-9a-f]{4})/ToUTF8(hex $1)/ige;
222 0 ▶ $rtnVal =~ s/\\(.)/$unescapeJSON{$1}||$1/sge;
Condition0%0/3
$unescapeJSON{$1} || $1
l!l&&r!l&&!r
000
MC/DC0%0/2
$unescapeJSON{$1} || $1
$unescapeJSON{$1} $1
Truth table0%0/3
A || B
A= $unescapeJSON{$1}B= $1
ABresult
1X1
011
000
223 # decode base64 (binary data) values
224 295 ▶ if ($rtnVal =~ /^base64:[A-Za-z0-9+\/]*={0,2}$/ and length($rtnVal) % 4 == 3) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rtnVal =~ m[^base64:[A-Za-z0-9+/]*={0,2}$] and length($rtnVal) % 4 == 3) 0 295 295
Condition33%1/3
$rtnVal =~ m[^base64:[A-Za-z0-9+/]*={0,2}$] and length($rtnVal) % 4 == 3
!ll&&!rl&&r
29500
MC/DC0%0/2
$rtnVal =~ m[^base64:[A-Za-z0-9+/]*={0,2}$] and length($rtnVal) % 4 == 3
$rtnVal =~ m[^base64:[A-Za-z0-9+/]*={0,2}$] length($rtnVal) % 4 == 3
Truth table33%1/3
A and B
A= $rtnVal =~ m[^base64:[A-Za-z0-9+/]*={0,2}$]B= length($rtnVal) % 4 == 3
ABresult
0X0
100
111
225 0 require Image::ExifTool::XMP;
226 0 $rtnVal = ${Image::ExifTool::XMP::DecodeBase64(substr($rtnVal,7))};
227 }
228 ▶ } elsif ($tok eq ']' or $tok eq '}' or $tok eq ',') {
Condition83%5/6
$tok eq "]" or $tok eq "}" or $tok eq ","
l!l&&r!l&&!r
8083
$tok eq "]" or $tok eq "}"
l!l&&r!l&&!r
5383
MC/DC66%2/3
$tok eq "]" or $tok eq "}" or $tok eq ","
$tok eq "]" $tok eq "}" $tok eq ","
Truth table75%3/4
A or B or C
A= $tok eq "]"B= $tok eq "}"C= $tok eq ","
ABCresult
1XX1
01X1
0011
0000
229 # return undef for empty object, array, or list item
230 # (empty list item actually not valid JSON)
231 8 pos($$buffPt) = pos($$buffPt) - 1;
232 } else { # number, 'true', 'false', 'null'
233 83 ▶ $$buffPt =~ /([\s:,\}\]])/g or $readMore = 1, next;
Branch: 1 branch
BranchTrueFalseTotal
$$buffPt =~ /([\s:,\}\]])/g or $readMore = 1, next 83 0 83
234 83 pos($$buffPt) = pos($$buffPt) - 1;
235 83 $rtnVal = $tok . substr($$buffPt, $pos, pos($$buffPt)-$pos);
236 }
237 510 last;
238 }
239 510 return $rtnVal;
240 }
241  
242 #------------------------------------------------------------------------------
243 # Read JSON file
244 # Inputs: 0) JSON file name, file ref, RAF ref or SCALAR ref, 1) database hash ref,
245 # 2) flag to delete "-" tags, 3) character set
246 # Returns: undef on success, or error string
247 sub ReadJSON($$;$$)
248 61 ▶{
Subroutine ReadJSON: called CC=17 SCAR=35.8
Pod documented
249 61 local $_;
250 61 my ($file, $database, $missingValue, $chset) = @_;
251 61 my ($raf, $openedFile);
252  
253 # initialize character set for converting "\uHHHH" chars
254 61 ▶ $charset = $chset || 'UTF8';
Condition50%1/2
$chset || 'UTF8'
l!l
610
MC/DC0%0/1
$chset || 'UTF8'
$chset
Truth table50%1/2
A
A= $chset
Aresult
11
00
255 61 ▶ if (UNIVERSAL::isa($file, 'File::RandomAccess')) {
Branch: 3 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($file, 'File::RandomAccess')) { } 61 0 61
elsif (ref $file eq 'GLOB') { } 0 0 0
elsif (ref $file eq 'SCALAR') { } 0 0 0
256 61 $raf = $file;
257 61 $file = 'JSON file';
258 } elsif (ref $file eq 'GLOB') {
259 0 $raf = File::RandomAccess->new($file);
260 0 $file = 'JSON file';
261 } elsif (ref $file eq 'SCALAR') {
262 0 $raf = File::RandomAccess->new($file);
263 0 $file = 'in memory';
264 } else {
265 0 ▶ open JSONFILE, $file or return "Error opening JSON file '${file}'";
Branch: 1 branch
BranchTrueFalseTotal
open JSONFILE, $file or return "Error opening JSON file '${file}'" 0 0 0
266 0 binmode JSONFILE;
267 0 $openedFile = 1;
268 0 $raf = File::RandomAccess->new(\*JSONFILE);
269 }
270 61 my $obj = ReadJSONObject($raf);
271 61 ▶ close JSONFILE if $openedFile;
Branch: 1 branch
BranchTrueFalseTotal
if $openedFile 0 61 61
272 61 ▶ unless (ref $obj eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $obj eq "ARRAY") 61 0 61
273 61 ▶ ref $obj eq 'HASH' or return "Format error in JSON file '${file}'";
Branch: 1 branch
BranchTrueFalseTotal
ref $obj eq "HASH" or return "Format error in JSON file '${file}'" 61 0 61
274 61 $obj = [ $obj ];
275 }
276 61 my ($info, $found);
277 61 foreach $info (@$obj) {
278 61 ▶ next unless ref $info eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $info eq "HASH" 0 61 61
279 # fix "SourceFile" case, or assume '*' if SourceFile not specified
280 61 ▶ unless (defined $$info{SourceFile}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $info->{"SourceFile"}) 61 0 61
281 61 my ($key) = grep /^SourceFile$/i, keys %$info;
282 61 ▶ if ($key) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key) { } 0 61 61
283 0 $$info{SourceFile} = $$info{$key};
284 0 delete $$info{$key};
285 } else {
286 61 $$info{SourceFile} = '*';
287 }
288 }
289 61 ▶ if (defined $missingValue) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $missingValue) 1 60 61
290 1 ▶ $$info{$_} eq $missingValue and $$info{$_} = undef foreach keys %$info;
Branch: 1 branch
BranchTrueFalseTotal
$info->{$_} eq $missingValue and $info->{$_} = undef 3 10 13
291 }
292 61 $$database{$$info{SourceFile}} = $info;
293 61 $found = 1;
294 }
295 61 ▶ return $found ? undef : "No valid JSON objects in '${file}'";
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 61 0 61
296 }
297  
298  
299 17 1; # end
300  
301 __END__
« Image/ExifTool/Photoshop.pm ↑ Summary Image/ExifTool/WritePDF.pl »