| 1 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # File: XMPStruct.pl | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Description: XMP structure support | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # Revisions: 01/01/2011 - P. Harvey Created | ||||||||||||||||||||||||||||||||||||||||||
| 7 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | package Image::ExifTool::XMP; | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 15 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 15 | ▶ | use vars qw(%specialStruct %stdXlatNS); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 15 | ▶ | use Image::ExifTool qw(:Utils); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 15 | ▶ | use Image::ExifTool::XMP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | sub SerializeStruct($$;$); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | sub InflateStruct($$;$); | ||||||||||||||||||||||||||||||||||||||||||
| 19 | sub DumpStruct($;$); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | sub CheckStruct($$$); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | sub AddNewStruct($$$$$$); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | sub ConvertStruct($$$$;$); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | sub EscapeJSON($;$); | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | # lookups for JSON characters that we escape specially | ||||||||||||||||||||||||||||||||||||||||||
| 26 | 15 | my %jsonChar = ( '"'=>'"', '\\'=>'\\', "\b"=>'b', "\f"=>'f', "\n"=>'n', "\r"=>'r', "\t"=>'t' ); | |||||||||||||||||||||||||||||||||||||||||
| 27 | 15 | my %jsonEsc = ( '"'=>'"', '\\'=>'\\', 'b'=>"\b", 'f'=>"\f", 'n'=>"\n", 'r'=>"\r", 't'=>"\t" ); | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 30 | # Serialize a structure (or other object) into a simple string | ||||||||||||||||||||||||||||||||||||||||||
| 31 | # Inputs: 0) ExifTool ref, 1) HASH ref, ARRAY ref, or SCALAR, 2) closing bracket (or undef) | ||||||||||||||||||||||||||||||||||||||||||
| 32 | # Returns: serialized structure string (in format specified by StructFormat option) | ||||||||||||||||||||||||||||||||||||||||||
| 33 | # eg) "{field=text with {braces|}|, and a comma, field2=val2,field3={field4=[a,b]}}" | ||||||||||||||||||||||||||||||||||||||||||
| 34 | sub SerializeStruct($$;$) | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SerializeStruct: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my ($et, $obj, $ket) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my ($key, $val, @vals, $rtnVal); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $sfmt = $et->Options('StructFormat'); | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if (ref $obj eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | # support hashes with ordered keys | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | foreach $key (Image::ExifTool::OrderedKeys($obj)) { | |||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $hdr = $sfmt ? EscapeJSON($key) . ':' : $key . '='; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | push @vals, $hdr . SerializeStruct($et, $$obj{$key}, '}'); | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $rtnVal = '{' . join(',', @vals) . '}'; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } elsif (ref $obj eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | foreach $val (@$obj) { | |||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | push @vals, SerializeStruct($et, $val, ']'); | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $rtnVal = '[' . join(',', @vals) . ']'; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } elsif (defined $obj) { | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | ▶ | $obj = $$obj if ref $obj eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | # escape necessary characters in string (closing bracket plus "," and "|") | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if ($sfmt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | $rtnVal = EscapeJSON($obj, $sfmt eq 'JSONQ'); | |||||||||||||||||||||||||||||||||||||||||
| 57 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my $pat = $ket ? "\\$ket|,|\\|" : ',|\\|'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ($rtnVal = $obj) =~ s/($pat)/|$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 60 | # also must escape opening bracket or whitespace at start of string | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $rtnVal =~ s/^([\s\[\{])/|$1/; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } elsif ($sfmt) { | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $rtnVal = 'null'; | |||||||||||||||||||||||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | $rtnVal = ''; # allow undefined list items | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | return $rtnVal; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 72 | # Inflate structure (or other object) from a serialized string | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # Inputs: 0) ExifTool ref, 1) reference to object in string form | ||||||||||||||||||||||||||||||||||||||||||
| 74 | # (serialized using the '|' escape, or JSON) | ||||||||||||||||||||||||||||||||||||||||||
| 75 | # 2) extra delimiter for scalar values delimiters | ||||||||||||||||||||||||||||||||||||||||||
| 76 | # Returns: 0) object as a SCALAR, HASH ref, or ARRAY ref (or undef on error), | ||||||||||||||||||||||||||||||||||||||||||
| 77 | # 1) warning string (or undef) | ||||||||||||||||||||||||||||||||||||||||||
| 78 | # Notes: modifies input string to remove parsed objects | ||||||||||||||||||||||||||||||||||||||||||
| 79 | sub InflateStruct($$;$) | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 109 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
InflateStruct: called CC=34 SCAR=52.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | 109 | my ($et, $obj, $delim) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 82 | 109 | my ($val, $warn, $part); | |||||||||||||||||||||||||||||||||||||||||
| 83 | 109 | my $sfmt = $et->Options('StructFormat'); | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 109 | ▶ | if ($$obj =~ s/^\s*\{//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 13 | my %struct; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 13 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 88 | 20 | ▶ | last unless $sfmt ? $$obj =~ s/^\s*"(.*?)"\s*://s : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | $$obj =~ s/^\s*([-\w:.]+#?)\s*=//s; | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 19 | my $tag = $1; | |||||||||||||||||||||||||||||||||||||||||
| 91 | 19 | my ($v, $w) = InflateStruct($et, $obj, '}'); | |||||||||||||||||||||||||||||||||||||||||
| 92 | 19 | ▶ | $warn = $w if $w and not $warn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$w and not $warn
MC/DC0%0/2
$w and not $warn
$w
not $warn
Truth table33%1/3
A and not(B)
A= $wB= not $warn
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 19 | ▶ | return(undef, $warn) unless defined $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 19 | $struct{$tag} = $v; | |||||||||||||||||||||||||||||||||||||||||
| 95 | # eat comma separator, or all done if there wasn't one | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 19 | ▶ | last unless $$obj =~ s/^\s*,//s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # eat closing brace and warn if we didn't find one | ||||||||||||||||||||||||||||||||||||||||||
| 99 | 13 | ▶ | unless ($$obj =~ s/^\s*\}//s or $warn) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$obj =~ s/^\s*\}//s or $warn
MC/DC0%0/2
$$obj =~ s/^\s*\}//s or $warn
$$obj =~ s/^\s*\}//s
$warn
Truth table33%1/3
A or B
A= $$obj =~ s/^\s*\}//sB= $warn
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | if (length $$obj) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | ($part = $$obj) =~ s/^\s*//s; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $part =~ s/[\x0d\x0a].*//s; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | $part = substr($part,0,27) . '...' if length($part) > 30; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $warn = "Invalid structure field at '${part}'"; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $warn = 'Missing closing brace for structure'; | |||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 13 | $val = \%struct; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } elsif ($$obj =~ s/^\s*\[//) { | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | my @list; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 5 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 113 | 9 | my ($v, $w) = InflateStruct($et, $obj, ']'); | |||||||||||||||||||||||||||||||||||||||||
| 114 | 9 | ▶ | $warn = $w if $w and not $warn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$w and not $warn
MC/DC0%0/2
$w and not $warn
$w
not $warn
Truth table33%1/3
A and not(B)
A= $wB= not $warn
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | 9 | ▶ | return(undef, $warn) unless defined $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 116 | 9 | push @list, $v; | |||||||||||||||||||||||||||||||||||||||||
| 117 | 9 | ▶ | last unless $$obj =~ s/^\s*,//s; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | # eat closing bracket and warn if we didn't find one | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 5 | ▶ | $$obj =~ s/^\s*\]//s or $warn or $warn = 'Missing closing bracket for list'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$$obj =~ s/^\s*\]//s or $warn
MC/DC0%0/2
$$obj =~ s/^\s*\]//s or $warn
$$obj =~ s/^\s*\]//s
$warn
Truth table33%1/3
A or B
A= $$obj =~ s/^\s*\]//sB= $warn
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | $val = \@list; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 91 | $$obj =~ s/^\s+//s; # remove leading whitespace | |||||||||||||||||||||||||||||||||||||||||
| 124 | 91 | ▶ | if ($sfmt) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | if ($$obj =~ s/^"//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $val = ''; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | while ($$obj =~ s/(.*?)"//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $val .= $1; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | last unless $val =~ /([\\]+)$/ and length($1) & 0x01; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$val =~ /([\\]+)$/ and length $1 & 1
MC/DC0%0/2
$val =~ /([\\]+)$/ and length $1 & 1
$val =~ /([\\]+)$/
length $1 & 1
Truth table0%0/3
A and B
A= $val =~ /([\\]+)$/B= length $1 & 1
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | substr($val, -1, 1) = '"'; # (was an escaped quote) | |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | if ($val =~ s/^base64://) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | $val = DecodeBase64($val); | |||||||||||||||||||||||||||||||||||||||||
| 134 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # un-escape characters in JSON string | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | $val =~ s/\\(.)/$jsonEsc{$1}||'\\'.$1/egs; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$jsonEsc{$1} || '\\' . $1
MC/DC0%0/1
$jsonEsc{$1} || '\\' . $1
$jsonEsc{$1}
Truth table0%0/2
A
A= $jsonEsc{$1}
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } elsif ($$obj =~ s/^(true|false)\b//) { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | $val = '"' . ucfirst($1) . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } elsif ($$obj =~ s/^([+-]?(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?)//) { | ||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | $val = $1; | |||||||||||||||||||||||||||||||||||||||||
| 142 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $warn or $warn = 'Unknown JSON object'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $val = '""'; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | # read scalar up to specified delimiter (or "," if not defined) | ||||||||||||||||||||||||||||||||||||||||||
| 148 | 91 | ▶ | $delim = $delim ? "\\$delim|,|\\||\$" : ',|\\||$'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 91 | $val = ''; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 91 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 151 | 91 | ▶ | $$obj =~ s/^(.*?)($delim)//s or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 91 | $val .= $1; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 91 | ▶ | last unless $2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | 27 | ▶ | $2 eq '|' or $$obj = $2 . $$obj, last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | $$obj =~ s/^(.)//s and $val .= $1; # add escaped character | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 109 | return($val, $warn); | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 163 | # Escape string for JSON | ||||||||||||||||||||||||||||||||||||||||||
| 164 | # Inputs: 0) string, 1) flag to force numbers to be quoted too | ||||||||||||||||||||||||||||||||||||||||||
| 165 | # Returns: Escaped string (quoted if necessary) | ||||||||||||||||||||||||||||||||||||||||||
| 166 | sub EscapeJSON($;$) | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
EscapeJSON: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my ($str, $quote) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | unless ($quote) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | return 'null' unless defined $str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 171 | # JSON boolean (true or false) | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | return lc($str) if $str =~ /^(true|false)$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | # JSON number (see json.org for numerical format) | ||||||||||||||||||||||||||||||||||||||||||
| 174 | # return $str if $str =~ /^-?(\d|[1-9]\d+)(\.\d+)?(e[-+]?\d+)?$/i; | ||||||||||||||||||||||||||||||||||||||||||
| 175 | # (these big numbers caused problems for some JSON parsers, so be more conservative) | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | return $str if $str =~ /^-?(\d|[1-9]\d{1,14})(\.\d{1,16})?(e[-+]?\d{1,3})?$/i; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | return '""' unless defined $str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | # encode JSON string in base64 if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | return '"base64:' . EncodeBase64($str, 1) . '"' if Image::ExifTool::IsUTF8(\$str) < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | # escape special characters | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | $str =~ s/(["\t\n\r\\])/\\$jsonChar{$1}/sg; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $str =~ tr/\0//d; # remove all nulls | |||||||||||||||||||||||||||||||||||||||||
| 184 | # escape other control characters with \u | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | $str =~ s/([\0-\x1f])/sprintf("\\u%.4X",ord $1)/sge; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | return '"' . $str . '"'; # return the quoted string | |||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 190 | # Get XMP language code from tag name string | ||||||||||||||||||||||||||||||||||||||||||
| 191 | # Inputs: 0) tag name string | ||||||||||||||||||||||||||||||||||||||||||
| 192 | # Returns: 0) separated tag name, 1) language code (in standard case), or '' if | ||||||||||||||||||||||||||||||||||||||||||
| 193 | # language code was 'x-default', or undef if the tag had no language code | ||||||||||||||||||||||||||||||||||||||||||
| 194 | sub GetLangCode($) | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GetLangCode: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 8 | my $tag = shift; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 8 | ▶ | if ($tag =~ /^(\w+)[-_]([a-z]{2,3}|[xi])([-_][a-z\d]{2,8}([-_][a-z\d]{1,8})*)?$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | # normalize case of language codes | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 8 | my ($tg, $langCode) = ($1, lc($2)); | |||||||||||||||||||||||||||||||||||||||||
| 200 | 8 | ▶ | $langCode .= (length($3) == 3 ? uc($3) : lc($3)) if $3; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 8 | $langCode =~ tr/_/-/; # RFC 3066 specifies '-' as a separator | |||||||||||||||||||||||||||||||||||||||||
| 202 | 8 | ▶ | $langCode = '' if lc($langCode) eq 'x-default'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 8 | return($tg, $langCode); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | return($tag, undef); | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # Debugging routine to dump a structure, list or scalar | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # Inputs: 0) scalar, ARRAY ref or HASH ref, 1) indent (or undef) | ||||||||||||||||||||||||||||||||||||||||||
| 212 | sub DumpStruct($;$) | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DumpStruct: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | local $_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my ($obj, $indent) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | $indent or $indent = ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | if (ref $obj eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | print "{\n"; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | foreach (Image::ExifTool::OrderedKeys($obj)) { | |||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | print "$indent $_ = "; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | DumpStruct($$obj{$_}, "$indent "); | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | print $indent, "},\n"; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } elsif (ref $obj eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | print "[\n"; | |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | foreach (@$obj) { | |||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | print "$indent "; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | DumpStruct($_, "$indent "); | |||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | print $indent, "],\n", | |||||||||||||||||||||||||||||||||||||||||
| 232 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | print "\"$obj\",\n"; | |||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 238 | # Recursively validate structure fields (tags) | ||||||||||||||||||||||||||||||||||||||||||
| 239 | # Inputs: 0) ExifTool ref, 1) Structure ref, 2) structure table definition ref | ||||||||||||||||||||||||||||||||||||||||||
| 240 | # Returns: 0) validated structure ref, 1) error string, or undef on success | ||||||||||||||||||||||||||||||||||||||||||
| 241 | # Notes: | ||||||||||||||||||||||||||||||||||||||||||
| 242 | # - fixes field names in structure and applies inverse conversions to values | ||||||||||||||||||||||||||||||||||||||||||
| 243 | # - copies structure to avoid interdependencies with calling code on referenced values | ||||||||||||||||||||||||||||||||||||||||||
| 244 | # - handles lang-alt tags, and '#' on field names | ||||||||||||||||||||||||||||||||||||||||||
| 245 | # - resets UTF-8 flag of SCALAR values | ||||||||||||||||||||||||||||||||||||||||||
| 246 | # - un-escapes for XML or HTML as per Escape option setting | ||||||||||||||||||||||||||||||||||||||||||
| 247 | sub CheckStruct($$$) | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 51 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CheckStruct: called CC=69 SCAR=50.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 249 | 51 | my ($et, $struct, $strTable) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||
| 251 | 51 | ▶ | my $strName = $$strTable{STRUCT_NAME} || ('XMP ' . RegisterNamespace($strTable)); | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$strTable->{'STRUCT_NAME'} || 'XMP ' . &RegisterNamespace($strTable)
MC/DC100%1/1
$strTable->{'STRUCT_NAME'} || 'XMP ' . &RegisterNamespace($strTable)
$strTable->{'STRUCT_NAME'}
Truth table100%2/2
A
A= $strTable->{'STRUCT_NAME'}
| |||||||||||||||||||||||||||||||||||||||||||
| 252 | 51 | ▶ | ref $struct eq 'HASH' or return wantarray ? (undef, "Expecting $strName structure") : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 51 | my ($key, $err, $warn, %copy, $rtnVal, $val); | |||||||||||||||||||||||||||||||||||||||||
| 255 | # copy the ordered keys if they exist | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 51 | ▶ | $copy{_ordered_keys_} = [ ] if $$struct{_ordered_keys_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | Key: | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 51 | foreach $key (Image::ExifTool::OrderedKeys($struct)) { | |||||||||||||||||||||||||||||||||||||||||
| 259 | 85 | my $tag = $key; | |||||||||||||||||||||||||||||||||||||||||
| 260 | # allow trailing '#' to disable print conversion on a per-field basis | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 85 | my ($type, $fieldInfo); | |||||||||||||||||||||||||||||||||||||||||
| 262 | 85 | ▶ | $type = 'ValueConv' if $tag =~ s/#$//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 85 | ▶ | $fieldInfo = $$strTable{$tag} unless $specialStruct{$tag}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | # fix case of field name if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 85 | ▶ | unless ($fieldInfo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | # (sort in reverse to get lower case (not special) tags first) | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 44 | my ($fix) = reverse sort grep /^$tag$/i, keys %$strTable; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 44 | ▶ | $fieldInfo = $$strTable{$tag = $fix} if $fix and not $specialStruct{$fix}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$fix and not $Image::ExifTool::XMP::specialStruct{$fix}
MC/DC50%1/2
$fix and not $Image::ExifTool::XMP::specialStruct{$fix}
$fix
not $Image::ExifTool::XMP::specialStruct{$fix}
Truth table66%2/3
A and not(B)
A= $fixB= not $Image::ExifTool::XMP::specialStruct{$fix}
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 85 | ▶ | until (ref $fieldInfo eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | # generate wildcard fields on the fly (eg. mwg-rs:Extensions) | ||||||||||||||||||||||||||||||||||||||||||
| 272 | 15 | ▶ | unless ($$strTable{NAMESPACE}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 10 | my ($grp, $tg, $langCode); | |||||||||||||||||||||||||||||||||||||||||
| 274 | 10 | ▶ | ($grp, $tg) = $tag =~ /^(.+):(.+)/ ? (lc $1, $2) : ('', $tag); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 275 | 10 | ▶ | undef $grp if $grp eq 'XMP'; # (a group of 'XMP' is implied) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 10 | require Image::ExifTool::TagLookup; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 10 | my @matches = Image::ExifTool::TagLookup::FindTagInfo($tg); | |||||||||||||||||||||||||||||||||||||||||
| 278 | # also look for lang-alt tags | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 10 | ▶ | unless (@matches) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 3 | ($tg, $langCode) = GetLangCode($tg); | |||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | ▶ | @matches = Image::ExifTool::TagLookup::FindTagInfo($tg) if defined $langCode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 10 | my ($tagInfo, $priority, $ti, $g1); | |||||||||||||||||||||||||||||||||||||||||
| 284 | # find best matching tag | ||||||||||||||||||||||||||||||||||||||||||
| 285 | 10 | foreach $ti (@matches) { | |||||||||||||||||||||||||||||||||||||||||
| 286 | 34 | my @grps = $et->GetGroup($ti); | |||||||||||||||||||||||||||||||||||||||||
| 287 | 34 | ▶ | next unless $grps[0] eq 'XMP'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 10 | ▶ | next if $grp and $grp ne lc $grps[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$grp and $grp ne lc $grps[1]
MC/DC0%0/2
$grp and $grp ne lc $grps[1]
$grp
$grp ne lc $grps[1]
Truth table66%2/3
A and B
A= $grpB= $grp ne lc $grps[1]
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | # must be lang-alt tag if we are writing an alternate language | ||||||||||||||||||||||||||||||||||||||||||
| 290 | 10 | ▶ | next if defined $langCode and not ($$ti{Writable} and $$ti{Writable} eq 'lang-alt'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
defined $langCode and not $ti->{"Writable"} && $ti->{"Writable"} eq "lang-alt"
$ti->{'Writable'} && $ti->{'Writable'} eq 'lang-alt'
MC/DC0%0/3
defined $langCode and not $ti->{"Writable"} && $ti->{"Writable"} eq "lang-alt"
defined $langCode
$ti->{'Writable'}
$ti->{'Writable'} eq 'lang-alt'
Truth table50%2/4
A and not(B && C)
A= defined $langCodeB= $ti->{'Writable'}C= $ti->{'Writable'} eq 'lang-alt'
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 10 | ▶ | my $pri = $$ti{Priority} || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ti->{'Priority'} || 1
MC/DC0%0/1
$ti->{'Priority'} || 1
$ti->{'Priority'}
Truth table50%1/2
A
A= $ti->{'Priority'}
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 10 | ▶ | $pri -= 10 if $$ti{Avoid}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 10 | ▶ | next if defined $priority and $priority >= $pri; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $priority and $priority >= $pri
MC/DC0%0/2
defined $priority and $priority >= $pri
defined $priority
$priority >= $pri
Truth table33%1/3
A and B
A= defined $priorityB= $priority >= $pri
| |||||||||||||||||||||||||||||||||||||||||||
| 294 | 10 | $priority = $pri; | |||||||||||||||||||||||||||||||||||||||||
| 295 | 10 | $tagInfo = $ti; | |||||||||||||||||||||||||||||||||||||||||
| 296 | 10 | $g1 = $grps[1]; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 10 | ▶ | $tagInfo or $warn = "'${tag}' is not a writable XMP tag", next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 10 | GetPropertyPath($tagInfo); # make sure property path is generated for this tag | |||||||||||||||||||||||||||||||||||||||||
| 300 | 10 | $tag = $$tagInfo{Name}; | |||||||||||||||||||||||||||||||||||||||||
| 301 | 10 | ▶ | $tag = "$g1:$tag" if $grp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 10 | ▶ | $tag .= "-$langCode" if $langCode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | 10 | $fieldInfo = $$strTable{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 304 | # create new structure field if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 305 | $fieldInfo or $fieldInfo = $$strTable{$tag} = { | ||||||||||||||||||||||||||||||||||||||||||
| 306 | %$tagInfo, # (also copies the necessary TagID and PropertyPath) | ||||||||||||||||||||||||||||||||||||||||||
| 307 | Namespace => $$tagInfo{Namespace} || $$tagInfo{Table}{NAMESPACE}, | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 10 | ▶ | LangCode => $langCode, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$tagInfo->{'Namespace'} || $tagInfo->{'Table'}{'NAMESPACE'}
MC/DC0%0/2
$tagInfo->{'Namespace'} || $tagInfo->{'Table'}{'NAMESPACE'}
$tagInfo->{'Namespace'}
$tagInfo->{'Table'}{'NAMESPACE'}
Truth table33%1/3
A || B
A= $tagInfo->{'Namespace'}B= $tagInfo->{'Table'}{'NAMESPACE'}
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 310 | # delete stuff we don't need (shouldn't cause harm, but better safe than sorry) | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # - need to keep StructType and Table in case we need to call AddStructType later | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 10 | delete $$fieldInfo{Description}; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 10 | delete $$fieldInfo{Groups}; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 10 | last; # write this dynamically-generated field | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | # generate lang-alt fields on the fly (eg. Iptc4xmpExt:AOTitle) | ||||||||||||||||||||||||||||||||||||||||||
| 317 | 5 | my ($tg, $langCode) = GetLangCode($tag); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 5 | ▶ | if (defined $langCode) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 5 | ▶ | $fieldInfo = $$strTable{$tg} unless $specialStruct{$tg}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 5 | ▶ | unless ($fieldInfo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 321 | 1 | my ($fix) = reverse sort grep /^$tg$/i, keys %$strTable; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 1 | ▶ | $fieldInfo = $$strTable{$tg = $fix} if $fix and not $specialStruct{$fix}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$fix and not $Image::ExifTool::XMP::specialStruct{$fix}
MC/DC0%0/2
$fix and not $Image::ExifTool::XMP::specialStruct{$fix}
$fix
not $Image::ExifTool::XMP::specialStruct{$fix}
Truth table33%1/3
A and not(B)
A= $fixB= not $Image::ExifTool::XMP::specialStruct{$fix}
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | 5 | ▶ | if (ref $fieldInfo eq 'HASH' and $$fieldInfo{Writable} and | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $fieldInfo eq "HASH" and $fieldInfo->{"Writable"} and $fieldInfo->{"Writable"} eq "lang-alt"
ref $fieldInfo eq "HASH" and $fieldInfo->{"Writable"}
MC/DC0%0/3
ref $fieldInfo eq "HASH" and $fieldInfo->{"Writable"} and $fieldInfo->{"Writable"} eq "lang-alt"
ref $fieldInfo eq "HASH"
$fieldInfo->{"Writable"}
$fieldInfo->{"Writable"} eq "lang-alt"
Truth table25%1/4
A and B and C
A= ref $fieldInfo eq "HASH"B= $fieldInfo->{"Writable"}C= $fieldInfo->{"Writable"} eq "lang-alt"
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | $$fieldInfo{Writable} eq 'lang-alt') | ||||||||||||||||||||||||||||||||||||||||||
| 326 | { | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 5 | my $srcInfo = $fieldInfo; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 5 | ▶ | $tag = $tg . '-' . $langCode if $langCode; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 5 | $fieldInfo = $$strTable{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 330 | # create new structure field if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 5 | ▶ | $fieldInfo or $fieldInfo = $$strTable{$tag} = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | %$srcInfo, | ||||||||||||||||||||||||||||||||||||||||||
| 333 | TagID => $tg, | ||||||||||||||||||||||||||||||||||||||||||
| 334 | LangCode => $langCode, | ||||||||||||||||||||||||||||||||||||||||||
| 335 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 5 | last; # write this lang-alt field | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $warn = "'${tag}' is not a field of $strName"; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | next Key; | |||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 85 | ▶ | if (ref $$struct{$key} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 10 | ▶ | $$fieldInfo{Struct} or $warn = "$tag is not a structure in $strName", next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | # recursively check this structure | ||||||||||||||||||||||||||||||||||||||||||
| 345 | 10 | ($val, $err) = CheckStruct($et, $$struct{$key}, $$fieldInfo{Struct}); | |||||||||||||||||||||||||||||||||||||||||
| 346 | 10 | ▶ | $err and $warn = $err, next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | 10 | $copy{$tag} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 348 | } elsif (ref $$struct{$key} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 349 | 13 | ▶ | $$fieldInfo{List} or $warn = "$tag is not a list in $strName", next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | # check all items in the list | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 13 | my ($item, @copy); | |||||||||||||||||||||||||||||||||||||||||
| 352 | 13 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 13 | foreach $item (@{$$struct{$key}}) { | |||||||||||||||||||||||||||||||||||||||||
| 354 | 21 | ▶ | if (not ref $item) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 13 | ▶ | $item = '' unless defined $item; # use empty string for missing items | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 13 | ▶ | if ($$fieldInfo{Struct}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 357 | # (allow empty structures) | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 2 | ▶ | $item =~ /^\s*$/ or $warn = "$tag items are not valid structures", next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 2 | $copy[$i] = { }; # create hash for empty structure | |||||||||||||||||||||||||||||||||||||||||
| 360 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 11 | $et->Sanitize(\$item); | |||||||||||||||||||||||||||||||||||||||||
| 362 | 11 | ($copy[$i],$err) = $et->ConvInv($item,$fieldInfo,$tag,$strName,$type,''); | |||||||||||||||||||||||||||||||||||||||||
| 363 | 11 | ▶ | $copy[$i] = '' unless defined $copy[$i]; # avoid undefined item | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 11 | ▶ | $err and $warn = $err, next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 11 | $err = CheckXMP($et, $fieldInfo, \$copy[$i]); | |||||||||||||||||||||||||||||||||||||||||
| 366 | 11 | ▶ | $err and $warn = "$err in $strName $tag", next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | } elsif (ref $item eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 8 | ▶ | $$fieldInfo{Struct} or $warn = "$tag is not a structure in $strName", next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 370 | 8 | ($copy[$i], $err) = CheckStruct($et, $item, $$fieldInfo{Struct}); | |||||||||||||||||||||||||||||||||||||||||
| 371 | 8 | ▶ | $err and $warn = $err, next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $warn = "Invalid value for $tag in $strName"; | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | next Key; | |||||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 21 | ++$i; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | 13 | $copy{$tag} = \@copy; | |||||||||||||||||||||||||||||||||||||||||
| 379 | } elsif ($$fieldInfo{Struct}) { | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | $warn = "Improperly formed structure in $strName $tag"; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 382 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 62 | $et->Sanitize(\$$struct{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 384 | 62 | ($val,$err) = $et->ConvInv($$struct{$key},$fieldInfo,$tag,$strName,$type,''); | |||||||||||||||||||||||||||||||||||||||||
| 385 | 62 | ▶ | $err and $warn = $err, next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | 62 | ▶ | next Key unless defined $val; # check for undefined | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 387 | 62 | $err = CheckXMP($et, $fieldInfo, \$val); | |||||||||||||||||||||||||||||||||||||||||
| 388 | 62 | ▶ | $err and $warn = "$err in $strName $tag", next Key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | # turn this into a list if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 390 | 62 | ▶ | $copy{$tag} = $$fieldInfo{List} ? [ $val ] : $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | ▶ | push @{$copy{_ordered_keys_}}, $tag if $copy{_ordered_keys_}; # save ordered keys | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | 51 | ▶ | if (%copy or not $warn) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
%copy or not $warn
MC/DC0%0/2
%copy or not $warn
%copy
not $warn
Truth table66%2/3
A or not(B)
A= %copyB= not $warn
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | 51 | $rtnVal = \%copy; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 51 | undef $err; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 51 | ▶ | $$et{CHECK_WARN} = $warn if $warn; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 398 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | $err = $warn; | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | 51 | ▶ | return wantarray ? ($rtnVal, $err) : $rtnVal; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 405 | # Delete matching structures from existing linearized XMP | ||||||||||||||||||||||||||||||||||||||||||
| 406 | # Inputs: 0) ExifTool ref, 1) capture hash ref, 2) structure path ref, | ||||||||||||||||||||||||||||||||||||||||||
| 407 | # 3) new value hash ref, 4) reference to change counter | ||||||||||||||||||||||||||||||||||||||||||
| 408 | # Returns: 0) delete flag, 1) list index of deleted structure if adding to list | ||||||||||||||||||||||||||||||||||||||||||
| 409 | # 2) flag set if structure existed | ||||||||||||||||||||||||||||||||||||||||||
| 410 | # Notes: updates path to new base path for structure to be added | ||||||||||||||||||||||||||||||||||||||||||
| 411 | sub DeleteStruct($$$$$) | ||||||||||||||||||||||||||||||||||||||||||
| 412 | 218 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DeleteStruct: called CC=37 SCAR=55.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 218 | my ($et, $capture, $pathPt, $nvHash, $changed) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 218 | my ($deleted, $added, $existed, $p, $pp, $val, $delPath); | |||||||||||||||||||||||||||||||||||||||||
| 415 | 218 | my (@structPaths, @matchingPaths, @delPaths); | |||||||||||||||||||||||||||||||||||||||||
| 416 | |||||||||||||||||||||||||||||||||||||||||||
| 417 | # find all existing elements belonging to this structure | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 218 | ($pp = $$pathPt) =~ s/ \d+/ \\d\+/g; | |||||||||||||||||||||||||||||||||||||||||
| 419 | 218 | @structPaths = sort grep(/^$pp(\/|$)/, keys %$capture); | |||||||||||||||||||||||||||||||||||||||||
| 420 | 218 | ▶ | $existed = 1 if @structPaths; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 421 | # delete only structures with matching fields if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 422 | 218 | ▶ | if ($$nvHash{DelValue}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 4 | ▶ | if (@{$$nvHash{DelValue}}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 4 | my $strTable = $$nvHash{TagInfo}{Struct}; | |||||||||||||||||||||||||||||||||||||||||
| 425 | # all fields must match corresponding elements in the same | ||||||||||||||||||||||||||||||||||||||||||
| 426 | # root structure for it to be deleted | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 4 | foreach $val (@{$$nvHash{DelValue}}) { | |||||||||||||||||||||||||||||||||||||||||
| 428 | 4 | ▶ | next unless ref $val eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my (%cap, $p2, %match); | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | next unless AddNewStruct(undef, undef, \%cap, $$pathPt, $val, $strTable); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | foreach $p (keys %cap) { | |||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | if ($p =~ / /) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | ($p2 = $p) =~ s/ \d+/ \\d\+/g; | |||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | @matchingPaths = sort grep(/^$p2$/, @structPaths); | |||||||||||||||||||||||||||||||||||||||||
| 435 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | push @matchingPaths, $p; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | foreach $p2 (@matchingPaths) { | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | $p2 =~ /^($pp)/ or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | # language attribute must also match if it exists | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my $attr = $cap{$p}[1]; | |||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | if ($$attr{'xml:lang'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my $a2 = $$capture{$p2}[1]; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | next unless $$a2{'xml:lang'} and $$a2{'xml:lang'} eq $$attr{'xml:lang'}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$a2->{"xml:lang"} and $a2->{"xml:lang"} eq $attr->{"xml:lang"}
MC/DC0%0/2
$a2->{"xml:lang"} and $a2->{"xml:lang"} eq $attr->{"xml:lang"}
$a2->{"xml:lang"}
$a2->{"xml:lang"} eq $attr->{"xml:lang"}
Truth table0%0/3
A and B
A= $a2->{"xml:lang"}B= $a2->{"xml:lang"} eq $attr->{"xml:lang"}
| |||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | if ($$capture{$p2} and $$capture{$p2}[0] eq $cap{$p}[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$capture->{$p2} and $capture->{$p2}[0] eq $cap{$p}[0]
MC/DC0%0/2
$capture->{$p2} and $capture->{$p2}[0] eq $cap{$p}[0]
$capture->{$p2}
$capture->{$p2}[0] eq $cap{$p}[0]
Truth table0%0/3
A and B
A= $capture->{$p2}B= $capture->{$p2}[0] eq $cap{$p}[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 447 | # ($1 contains root path for this structure) | ||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | $match{$1} = ($match{$1} || 0) + 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$match{$1} || 0
MC/DC0%0/1
$match{$1} || 0
$match{$1}
Truth table0%0/2
A
A= $match{$1}
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | my $num = scalar(keys %cap); | |||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | foreach $p (keys %match) { | |||||||||||||||||||||||||||||||||||||||||
| 454 | # do nothing unless all fields matched the same structure | ||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | next unless $match{$p} == $num; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | # delete all elements of this structure | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | foreach $p2 (@structPaths) { | |||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | ▶ | push @delPaths, $p2 if $p2 =~ /^$p/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | # remember path of first deleted structure | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | ▶ | $delPath = $p if not $delPath or $delPath gt $p; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $delPath or $delPath gt $p
MC/DC0%0/2
not $delPath or $delPath gt $p
not $delPath
$delPath gt $p
Truth table0%0/3
not(A) or B
A= not $delPathB= $delPath gt $p
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | } # (else don't delete anything) | ||||||||||||||||||||||||||||||||||||||||||
| 465 | } elsif (@structPaths) { | ||||||||||||||||||||||||||||||||||||||||||
| 466 | 2 | @delPaths = @structPaths; # delete all | |||||||||||||||||||||||||||||||||||||||||
| 467 | 2 | $structPaths[0] =~ /^($pp)/; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 2 | $delPath = $1; | |||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 218 | ▶ | if (@delPaths) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 2 | my $verbose = $et->Options('Verbose'); | |||||||||||||||||||||||||||||||||||||||||
| 472 | 2 | ▶ | @delPaths = sort @delPaths if $verbose > 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 2 | foreach $p (@delPaths) { | |||||||||||||||||||||||||||||||||||||||||
| 474 | 6 | ▶ | if ($verbose > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | my $p2 = $p; | |||||||||||||||||||||||||||||||||||||||||
| 476 | 0 | ▶ | $p2 =~ s/^(\w+)/$stdXlatNS{$1} || $1/e; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Image::ExifTool::XMP::stdXlatNS{$1} || $1
MC/DC0%0/2
$Image::ExifTool::XMP::stdXlatNS{$1} || $1
$Image::ExifTool::XMP::stdXlatNS{$1}
$1
Truth table0%0/3
A || B
A= $Image::ExifTool::XMP::stdXlatNS{$1}B= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 0 | $et->VerboseValue("- XMP-$p2", $$capture{$p}[0]); | |||||||||||||||||||||||||||||||||||||||||
| 478 | } | ||||||||||||||||||||||||||||||||||||||||||
| 479 | 6 | delete $$capture{$p}; | |||||||||||||||||||||||||||||||||||||||||
| 480 | 6 | $deleted = 1; | |||||||||||||||||||||||||||||||||||||||||
| 481 | 6 | ++$$changed; | |||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 2 | ▶ | $delPath or warn("Internal error 1 in DeleteStruct\n"), return(undef,undef,$existed); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 2 | $$pathPt = $delPath; # return path of first element deleted | |||||||||||||||||||||||||||||||||||||||||
| 485 | } elsif ($$nvHash{TagInfo}{List}) { | ||||||||||||||||||||||||||||||||||||||||||
| 486 | # NOTE: we don't yet properly handle lang-alt elements!!!! | ||||||||||||||||||||||||||||||||||||||||||
| 487 | 161 | ▶ | if (@structPaths) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 488 | 1 | ▶ | $structPaths[-1] =~ /^($pp)/ or warn("Internal error 2 in DeleteStruct\n"), return(undef,undef,$existed); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | my $path = $1; | |||||||||||||||||||||||||||||||||||||||||
| 490 | # delete any improperly formatted xmp | ||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | ▶ | if ($$capture{$path}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $cap = $$capture{$path}; | |||||||||||||||||||||||||||||||||||||||||
| 493 | # an error unless this was an empty structure | ||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | $et->Error("Improperly structured XMP ($path)",1) if ref $cap ne 'ARRAY' or $$cap[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $cap ne "ARRAY" or $cap->[0]
MC/DC0%0/2
ref $cap ne "ARRAY" or $cap->[0]
ref $cap ne "ARRAY"
$cap->[0]
Truth table0%0/3
A or B
A= ref $cap ne "ARRAY"B= $cap->[0]
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | delete $$capture{$path}; | |||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | # (match last index to put in same lang-alt list for Bag of lang-alt items) | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 1 | ▶ | $path =~ m/.* (\d+)/g or warn("Internal error 3 in DeleteStruct\n"), return(undef,undef,$existed); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | $added = $1; | |||||||||||||||||||||||||||||||||||||||||
| 500 | # add after last item in list | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | my $len = length $added; | |||||||||||||||||||||||||||||||||||||||||
| 502 | 1 | my $pos = pos($path) - $len; | |||||||||||||||||||||||||||||||||||||||||
| 503 | 1 | my $nxt = substr($added, 1) + 1; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 1 | substr($path, $pos, $len) = length($nxt) . $nxt; | |||||||||||||||||||||||||||||||||||||||||
| 505 | 1 | $$pathPt = $path; | |||||||||||||||||||||||||||||||||||||||||
| 506 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 160 | $added = '10'; | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | } | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 218 | return($deleted, $added, $existed); | |||||||||||||||||||||||||||||||||||||||||
| 511 | } | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 514 | # Add new element to XMP capture hash | ||||||||||||||||||||||||||||||||||||||||||
| 515 | # Inputs: 0) ExifTool ref, 1) TagInfo ref, 2) capture hash ref, | ||||||||||||||||||||||||||||||||||||||||||
| 516 | # 3) resource path, 4) value ref, 5) hash ref for last used index numbers | ||||||||||||||||||||||||||||||||||||||||||
| 517 | sub AddNewTag($$$$$$) | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 71 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AddNewTag: called CC=10 SCAR=24.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | 71 | my ($et, $tagInfo, $capture, $path, $valPtr, $langIdx) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 520 | 71 | my $val = EscapeXML($$valPtr); | |||||||||||||||||||||||||||||||||||||||||
| 521 | 71 | my %attrs; | |||||||||||||||||||||||||||||||||||||||||
| 522 | # support writing RDF "resource" values | ||||||||||||||||||||||||||||||||||||||||||
| 523 | 71 | ▶ | if ($$tagInfo{Resource}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 2 | $attrs{'rdf:resource'} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 525 | 2 | $val = ''; | |||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||
| 527 | 71 | ▶ | if ($$tagInfo{Writable} and $$tagInfo{Writable} eq 'lang-alt') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tagInfo->{"Writable"} and $tagInfo->{"Writable"} eq "lang-alt"
MC/DC100%2/2
$tagInfo->{"Writable"} and $tagInfo->{"Writable"} eq "lang-alt"
$tagInfo->{"Writable"}
$tagInfo->{"Writable"} eq "lang-alt"
Truth table100%3/3
A and B
A= $tagInfo->{"Writable"}B= $tagInfo->{"Writable"} eq "lang-alt"
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | # write the lang-alt tag | ||||||||||||||||||||||||||||||||||||||||||
| 529 | 20 | my $langCode = $$tagInfo{LangCode}; | |||||||||||||||||||||||||||||||||||||||||
| 530 | # add indexed lang-alt list properties | ||||||||||||||||||||||||||||||||||||||||||
| 531 | 20 | ▶ | my $i = $$langIdx{$path} || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$langIdx->{$path} || 0
MC/DC100%1/1
$langIdx->{$path} || 0
$langIdx->{$path}
Truth table100%2/2
A
A= $langIdx->{$path}
| |||||||||||||||||||||||||||||||||||||||||||
| 532 | 20 | $$langIdx{$path} = $i + 1; # save next list index | |||||||||||||||||||||||||||||||||||||||||
| 533 | 20 | ▶ | if ($i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 8 | my $idx = length($i) . $i; | |||||||||||||||||||||||||||||||||||||||||
| 535 | 8 | $path =~ s/(.*) \d+/$1 $idx/; # set list index | |||||||||||||||||||||||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||||||||||||||||||||||
| 537 | 20 | ▶ | $attrs{'xml:lang'} = $langCode || 'x-default'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$langCode || 'x-default'
MC/DC100%1/1
$langCode || 'x-default'
$langCode
Truth table100%2/2
A
A= $langCode
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 71 | $$capture{$path} = [ $val, \%attrs ]; | |||||||||||||||||||||||||||||||||||||||||
| 540 | # print verbose message | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 71 | ▶ | if ($et and $et->Options('Verbose') > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$et and $et->Options("Verbose") > 1
MC/DC0%0/2
$et and $et->Options("Verbose") > 1
$et
$et->Options("Verbose") > 1
Truth table33%1/3
A and B
A= $etB= $et->Options("Verbose") > 1
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | my $p = $path; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | ▶ | $p =~ s/^(\w+)/$stdXlatNS{$1} || $1/e; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Image::ExifTool::XMP::stdXlatNS{$1} || $1
MC/DC0%0/2
$Image::ExifTool::XMP::stdXlatNS{$1} || $1
$Image::ExifTool::XMP::stdXlatNS{$1}
$1
Truth table0%0/3
A || B
A= $Image::ExifTool::XMP::stdXlatNS{$1}B= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | $et->VerboseValue("+ XMP-$p", $val); | |||||||||||||||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 549 | # Add new structure to capture hash for writing | ||||||||||||||||||||||||||||||||||||||||||
| 550 | # Inputs: 0) ExifTool object ref (or undef for no warnings), | ||||||||||||||||||||||||||||||||||||||||||
| 551 | # 1) tagInfo ref (or undef if no ExifTool), 2) capture hash ref, | ||||||||||||||||||||||||||||||||||||||||||
| 552 | # 3) base path, 4) struct ref, 5) struct hash ref | ||||||||||||||||||||||||||||||||||||||||||
| 553 | # Returns: number of tags changed | ||||||||||||||||||||||||||||||||||||||||||
| 554 | # Notes: Escapes values for XML | ||||||||||||||||||||||||||||||||||||||||||
| 555 | sub AddNewStruct($$$$$$) | ||||||||||||||||||||||||||||||||||||||||||
| 556 | 50 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AddNewStruct: called CC=33 SCAR=36.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | 50 | my ($et, $tagInfo, $capture, $basePath, $struct, $strTable) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 558 | 50 | ▶ | my $verbose = $et ? $et->Options('Verbose') : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 559 | 50 | my ($tag, %langIdx); | |||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | 50 | ▶ | my $ns = $$strTable{NAMESPACE} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$strTable->{'NAMESPACE'} || ''
MC/DC100%1/1
$strTable->{'NAMESPACE'} || ''
$strTable->{'NAMESPACE'}
Truth table100%2/2
A
A= $strTable->{'NAMESPACE'}
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 50 | my $changed = 0; | |||||||||||||||||||||||||||||||||||||||||
| 563 | |||||||||||||||||||||||||||||||||||||||||||
| 564 | # add dummy field to allow empty structures (name starts with '~' so it will come | ||||||||||||||||||||||||||||||||||||||||||
| 565 | # after all valid structure fields, which is necessary when serializing the XMP later) | ||||||||||||||||||||||||||||||||||||||||||
| 566 | 50 | ▶ | %$struct or $$struct{'~dummy~'} = ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 50 | foreach $tag (Image::ExifTool::OrderedKeys($struct)) { | |||||||||||||||||||||||||||||||||||||||||
| 569 | 85 | my $fieldInfo = $$strTable{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 570 | 85 | ▶ | unless ($fieldInfo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | 3 | ▶ | next unless $tag eq '~dummy~'; # check for dummy field | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | 3 | $fieldInfo = { }; # create dummy field info for dummy structure | |||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 85 | my $val = $$struct{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 575 | 85 | my $propPath = $$fieldInfo{PropertyPath}; | |||||||||||||||||||||||||||||||||||||||||
| 576 | 85 | ▶ | unless ($propPath) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 577 | 37 | ▶ | $propPath = ($$fieldInfo{Namespace} || $ns) . ':' . ($$fieldInfo{TagID} || $tag); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$fieldInfo->{'Namespace'} || $ns
$fieldInfo->{'TagID'} || $tag
MC/DC0%0/2
$fieldInfo->{'Namespace'} || $ns
$fieldInfo->{'Namespace'}
$ns
MC/DC0%0/2
$fieldInfo->{'TagID'} || $tag
$fieldInfo->{'TagID'}
$tag
Truth table66%2/3
A || B
A= $fieldInfo->{'Namespace'}B= $ns
Truth table66%2/3
A || B
A= $fieldInfo->{'TagID'}B= $tag
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | 37 | ▶ | if ($$fieldInfo{List}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 579 | 7 | $propPath .= "/rdf:$$fieldInfo{List}/rdf:li 10"; | |||||||||||||||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||||||||||||||
| 581 | 37 | ▶ | if ($$fieldInfo{Writable} and $$fieldInfo{Writable} eq 'lang-alt') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$fieldInfo->{"Writable"} and $fieldInfo->{"Writable"} eq "lang-alt"
MC/DC100%2/2
$fieldInfo->{"Writable"} and $fieldInfo->{"Writable"} eq "lang-alt"
$fieldInfo->{"Writable"}
$fieldInfo->{"Writable"} eq "lang-alt"
Truth table100%3/3
A and B
A= $fieldInfo->{"Writable"}B= $fieldInfo->{"Writable"} eq "lang-alt"
| |||||||||||||||||||||||||||||||||||||||||||
| 582 | 7 | $propPath .= "/rdf:Alt/rdf:li 10"; | |||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||
| 584 | 37 | $$fieldInfo{PropertyPath} = $propPath; # save for next time | |||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 85 | my $path = $basePath . '/' . ConformPathToNamespace($et, $propPath); | |||||||||||||||||||||||||||||||||||||||||
| 587 | 85 | my $addedTag; | |||||||||||||||||||||||||||||||||||||||||
| 588 | 85 | ▶ | if (ref $val eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 589 | 10 | ▶ | my $subStruct = $$fieldInfo{Struct} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | 10 | $changed += AddNewStruct($et, $tagInfo, $capture, $path, $val, $subStruct); | |||||||||||||||||||||||||||||||||||||||||
| 591 | } elsif (ref $val eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 592 | 15 | ▶ | next unless $$fieldInfo{List}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | 15 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 15 | my ($item, $p); | |||||||||||||||||||||||||||||||||||||||||
| 595 | 15 | my $level = scalar(() = ($propPath =~ / \d+/g)); | |||||||||||||||||||||||||||||||||||||||||
| 596 | # loop through all list items (note: can't yet write multi-dimensional lists) | ||||||||||||||||||||||||||||||||||||||||||
| 597 | 15 | foreach $item (@{$val}) { | |||||||||||||||||||||||||||||||||||||||||
| 598 | 23 | ▶ | if ($i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 599 | # update first index in field property (may be list of lang-alt lists) | ||||||||||||||||||||||||||||||||||||||||||
| 600 | 8 | $p = ConformPathToNamespace($et, $propPath); | |||||||||||||||||||||||||||||||||||||||||
| 601 | 8 | my $idx = length($i) . $i; | |||||||||||||||||||||||||||||||||||||||||
| 602 | 8 | $p =~ s/ \d+/ $idx/; | |||||||||||||||||||||||||||||||||||||||||
| 603 | 8 | $p = "$basePath/$p"; | |||||||||||||||||||||||||||||||||||||||||
| 604 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 605 | 15 | $p = $path; | |||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||
| 607 | 23 | ▶ | if (ref $item eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 608 | 10 | ▶ | my $subStruct = $$fieldInfo{Struct} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 609 | 10 | ▶ | AddNewStruct($et, $tagInfo, $capture, $p, $item, $subStruct) or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 610 | # don't write empty items in upper-level list | ||||||||||||||||||||||||||||||||||||||||||
| 611 | ▶ | } elsif (length $item or (defined $item and $level == 1)) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition50%3/6
length $item or defined $item and $level == 1
defined $item and $level == 1
MC/DC33%1/3
length $item or defined $item and $level == 1
length $item
defined $item
$level == 1
Truth table50%2/4
A or B and C
A= length $itemB= defined $itemC= $level == 1
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | 11 | AddNewTag($et, $fieldInfo, $capture, $p, \$item, \%langIdx); | |||||||||||||||||||||||||||||||||||||||||
| 613 | 11 | $addedTag = 1; | |||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 615 | 23 | ++$changed; | |||||||||||||||||||||||||||||||||||||||||
| 616 | 23 | ++$i; | |||||||||||||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||||||||||||||
| 618 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 60 | AddNewTag($et, $fieldInfo, $capture, $path, \$val, \%langIdx); | |||||||||||||||||||||||||||||||||||||||||
| 620 | 60 | $addedTag = 1; | |||||||||||||||||||||||||||||||||||||||||
| 621 | 60 | ++$changed; | |||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||
| 623 | # this is tricky, but we must add the rdf:type for contained structures | ||||||||||||||||||||||||||||||||||||||||||
| 624 | # in the case that a whole hierarchy was added at once by writing a | ||||||||||||||||||||||||||||||||||||||||||
| 625 | # flattened tag inside a variable-namespace structure | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 85 | ▶ | if ($addedTag and $$fieldInfo{StructType} and $$fieldInfo{Table}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$addedTag and $fieldInfo->{"StructType"} and $fieldInfo->{"Table"}
$addedTag and $fieldInfo->{"StructType"}
MC/DC66%2/3
$addedTag and $fieldInfo->{"StructType"} and $fieldInfo->{"Table"}
$addedTag
$fieldInfo->{"StructType"}
$fieldInfo->{"Table"}
Truth table75%3/4
A and B and C
A= $addedTagB= $fieldInfo->{"StructType"}C= $fieldInfo->{"Table"}
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | 1 | AddStructType($et, $$fieldInfo{Table}, $capture, $propPath, $basePath); | |||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||
| 629 | } | ||||||||||||||||||||||||||||||||||||||||||
| 630 | # add 'rdf:type' property if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 631 | 50 | ▶ | if ($$strTable{TYPE} and $changed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$strTable->{"TYPE"} and $changed
MC/DC50%1/2
$strTable->{"TYPE"} and $changed
$strTable->{"TYPE"}
$changed
Truth table66%2/3
A and B
A= $strTable->{"TYPE"}B= $changed
| |||||||||||||||||||||||||||||||||||||||||||
| 632 | 3 | my $path = $basePath . '/' . ConformPathToNamespace($et, "rdf:type"); | |||||||||||||||||||||||||||||||||||||||||
| 633 | 3 | ▶ | unless ($$capture{$path}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | 3 | $$capture{$path} = [ '', { 'rdf:resource' => $$strTable{TYPE} } ]; | |||||||||||||||||||||||||||||||||||||||||
| 635 | 3 | ▶ | if ($verbose > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | my $p = $path; | |||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | ▶ | $p =~ s/^(\w+)/$stdXlatNS{$1} || $1/e; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$Image::ExifTool::XMP::stdXlatNS{$1} || $1
MC/DC0%0/2
$Image::ExifTool::XMP::stdXlatNS{$1} || $1
$Image::ExifTool::XMP::stdXlatNS{$1}
$1
Truth table0%0/3
A || B
A= $Image::ExifTool::XMP::stdXlatNS{$1}B= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | $et->VerboseValue("+ XMP-$p", $$strTable{TYPE}); | |||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | } | ||||||||||||||||||||||||||||||||||||||||||
| 641 | } | ||||||||||||||||||||||||||||||||||||||||||
| 642 | 50 | return $changed; | |||||||||||||||||||||||||||||||||||||||||
| 643 | } | ||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||
| 645 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 646 | # Convert structure field values for printing | ||||||||||||||||||||||||||||||||||||||||||
| 647 | # Inputs: 0) ExifTool ref, 1) tagInfo ref for structure tag, 2) value, | ||||||||||||||||||||||||||||||||||||||||||
| 648 | # 3) conversion type: PrintConv, ValueConv or Raw (Both not allowed) | ||||||||||||||||||||||||||||||||||||||||||
| 649 | # 4) tagID of parent structure (needed only if there was no flattened tag) | ||||||||||||||||||||||||||||||||||||||||||
| 650 | # Notes: Makes a copy of the hash so any applied escapes won't affect raw values | ||||||||||||||||||||||||||||||||||||||||||
| 651 | sub ConvertStruct($$$$;$) | ||||||||||||||||||||||||||||||||||||||||||
| 652 | 204 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ConvertStruct: called CC=16 SCAR=28.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 653 | 204 | my ($et, $tagInfo, $value, $type, $parentID) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 654 | 204 | ▶ | if (ref $value eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 655 | 108 | my (%struct, $key); | |||||||||||||||||||||||||||||||||||||||||
| 656 | 108 | my $table = $$tagInfo{Table}; | |||||||||||||||||||||||||||||||||||||||||
| 657 | 108 | ▶ | $parentID = $$tagInfo{TagID} unless $parentID; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 108 | ▶ | $struct{_ordered_keys_} = [ ] if $$value{_ordered_keys_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 659 | 108 | foreach $key (Image::ExifTool::OrderedKeys($value)) { | |||||||||||||||||||||||||||||||||||||||||
| 660 | 212 | my $tagID = $parentID . ucfirst($key); | |||||||||||||||||||||||||||||||||||||||||
| 661 | 212 | my $flatInfo = $$table{$tagID}; | |||||||||||||||||||||||||||||||||||||||||
| 662 | 212 | ▶ | unless ($flatInfo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 663 | # handle variable-namespace structures | ||||||||||||||||||||||||||||||||||||||||||
| 664 | 16 | ▶ | if ($key =~ /^XMP-(.*?:)(.*)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 665 | 13 | $tagID = $1 . $parentID . ucfirst($2); | |||||||||||||||||||||||||||||||||||||||||
| 666 | 13 | $flatInfo = $$table{$tagID}; | |||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||
| 668 | 16 | ▶ | $flatInfo or $flatInfo = $tagInfo; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | } | ||||||||||||||||||||||||||||||||||||||||||
| 670 | 212 | my $v = $$value{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 671 | 212 | ▶ | if (ref $v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 672 | 48 | $v = ConvertStruct($et, $flatInfo, $v, $type, $tagID); | |||||||||||||||||||||||||||||||||||||||||
| 673 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 674 | 164 | $v = $et->GetValue($flatInfo, $type, $v); | |||||||||||||||||||||||||||||||||||||||||
| 675 | } | ||||||||||||||||||||||||||||||||||||||||||
| 676 | 212 | ▶ | if (defined $v) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 677 | 212 | $struct{$key} = $v; # save the converted value | |||||||||||||||||||||||||||||||||||||||||
| 678 | # maintain ordered keys if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 679 | 212 | ▶ | push @{$struct{_ordered_keys_}}, $key if $struct{_ordered_keys_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | } | ||||||||||||||||||||||||||||||||||||||||||
| 681 | } | ||||||||||||||||||||||||||||||||||||||||||
| 682 | 108 | return \%struct; | |||||||||||||||||||||||||||||||||||||||||
| 683 | } elsif (ref $value eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 684 | 66 | ▶ | if (defined $$et{OPTIONS}{ListItem}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 0 | my $li = $$et{OPTIONS}{ListItem}; | |||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | return undef unless defined $$value[$li]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | 0 | undef $$et{OPTIONS}{ListItem}; # only do top-level list | |||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | my $val = ConvertStruct($et, $tagInfo, $$value[$li], $type, $parentID); | |||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | $$et{OPTIONS}{ListItem} = $li; | |||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | return $val; | |||||||||||||||||||||||||||||||||||||||||
| 691 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 692 | 66 | my (@list, $val); | |||||||||||||||||||||||||||||||||||||||||
| 693 | 66 | foreach $val (@$value) { | |||||||||||||||||||||||||||||||||||||||||
| 694 | 98 | my $v = ConvertStruct($et, $tagInfo, $val, $type, $parentID); | |||||||||||||||||||||||||||||||||||||||||
| 695 | 98 | ▶ | push @list, $v if defined $v; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 696 | } | ||||||||||||||||||||||||||||||||||||||||||
| 697 | 66 | return \@list; | |||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||
| 699 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 700 | 30 | return $et->GetValue($tagInfo, $type, $value); | |||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||
| 704 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||||||||||||||||
| 705 | # Restore XMP structures in extracted information | ||||||||||||||||||||||||||||||||||||||||||
| 706 | # Inputs: 0) ExifTool object ref, 1) flag to keep original flattened tags | ||||||||||||||||||||||||||||||||||||||||||
| 707 | # Notes: also restores lists (including multi-dimensional) | ||||||||||||||||||||||||||||||||||||||||||
| 708 | sub RestoreStruct($;$) | ||||||||||||||||||||||||||||||||||||||||||
| 709 | 28 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
RestoreStruct: called CC=62 SCAR=46.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 710 | 28 | local $_; | |||||||||||||||||||||||||||||||||||||||||
| 711 | 28 | my ($et, $keepFlat) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 712 | 28 | my ($key, %structs, %var, %lists, $si, %listKeys, @siList); | |||||||||||||||||||||||||||||||||||||||||
| 713 | 28 | my $valueHash = $$et{VALUE}; | |||||||||||||||||||||||||||||||||||||||||
| 714 | 28 | my $fileOrder = $$et{FILE_ORDER}; | |||||||||||||||||||||||||||||||||||||||||
| 715 | 28 | my $tagExtra = $$et{TAG_EXTRA}; | |||||||||||||||||||||||||||||||||||||||||
| 716 | 28 | foreach $key (keys %{$$et{TAG_INFO}}) { | |||||||||||||||||||||||||||||||||||||||||
| 717 | 2326 | ▶ | my $structProps = $$tagExtra{$key}{Struct} or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 718 | 329 | delete $$tagExtra{$key}{Struct}; # (don't re-use) | |||||||||||||||||||||||||||||||||||||||||
| 719 | 329 | my $tagInfo = $$et{TAG_INFO}{$key}; # tagInfo for flattened tag | |||||||||||||||||||||||||||||||||||||||||
| 720 | 329 | my $table = $$tagInfo{Table}; | |||||||||||||||||||||||||||||||||||||||||
| 721 | 329 | my $prop = shift @$structProps; | |||||||||||||||||||||||||||||||||||||||||
| 722 | 329 | my $tag = $$prop[0]; | |||||||||||||||||||||||||||||||||||||||||
| 723 | # get reference to structure tag (or normal list tag if not a structure) | ||||||||||||||||||||||||||||||||||||||||||
| 724 | 329 | ▶ | my $strInfo = @$structProps ? $$table{$tag} : $tagInfo; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 725 | 329 | ▶ | if ($strInfo) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 726 | 326 | ▶ | ref $strInfo eq 'HASH' or next; # (just to be safe) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 727 | 326 | ▶ | if (@$structProps and not $$strInfo{Struct}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$structProps and not $strInfo->{"Struct"}
MC/DC0%0/2
@$structProps and not $strInfo->{"Struct"}
@$structProps
not $strInfo->{"Struct"}
Truth table66%2/3
A and not(B)
A= @$structPropsB= not $strInfo->{"Struct"}
| |||||||||||||||||||||||||||||||||||||||||||
| 728 | # this could happen for invalid XMP containing mixed lists | ||||||||||||||||||||||||||||||||||||||||||
| 729 | # (or for something like this -- what should we do here?: | ||||||||||||||||||||||||||||||||||||||||||
| 730 | # <meta:user-defined meta:name="License">test</meta:user-defined>) | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | ▶ | $et->Warn("$$strInfo{Name} is not a structure!") unless $$et{NO_STRUCT_WARN}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 732 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||
| 734 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 735 | # create new entry in tag table for this structure | ||||||||||||||||||||||||||||||||||||||||||
| 736 | 3 | ▶ | my $g1 = $$table{GROUPS}{0} || 'XMP'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$table->{'GROUPS'}{'0'} || 'XMP'
MC/DC0%0/1
$table->{'GROUPS'}{'0'} || 'XMP'
$table->{'GROUPS'}{'0'}
Truth table50%1/2
A
A= $table->{'GROUPS'}{'0'}
| |||||||||||||||||||||||||||||||||||||||||||
| 737 | 3 | my $name = $tag; | |||||||||||||||||||||||||||||||||||||||||
| 738 | # tag keys will have a group 1 prefix when coming from import of XML from -X option | ||||||||||||||||||||||||||||||||||||||||||
| 739 | 3 | ▶ | if ($tag =~ /(.+):(.+)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 740 | 3 | my $ns; | |||||||||||||||||||||||||||||||||||||||||
| 741 | 3 | ($ns, $name) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 742 | 3 | $ns =~ s/^XMP-//; # remove leading "XMP-" if it exists because we add it later | |||||||||||||||||||||||||||||||||||||||||
| 743 | 3 | ▶ | $ns = $stdXlatNS{$ns} if $stdXlatNS{$ns}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | 3 | $g1 .= "-$ns"; | |||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||
| 746 | $strInfo = { | ||||||||||||||||||||||||||||||||||||||||||
| 747 | 3 | Name => ucfirst $name, | |||||||||||||||||||||||||||||||||||||||||
| 748 | Groups => { 1 => $g1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 749 | Struct => 'Unknown', | ||||||||||||||||||||||||||||||||||||||||||
| 750 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 751 | # add Struct entry if this is a structure | ||||||||||||||||||||||||||||||||||||||||||
| 752 | 3 | ▶ | if (@$structProps) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 753 | # this is a structure | ||||||||||||||||||||||||||||||||||||||||||
| 754 | 3 | ▶ | $$strInfo{Struct} = { STRUCT_NAME => 'XMP Unknown' } if @$structProps; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 755 | } elsif ($$tagInfo{LangCode}) { | ||||||||||||||||||||||||||||||||||||||||||
| 756 | # this is lang-alt list | ||||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | $tag = $tag . '-' . $$tagInfo{LangCode}; | |||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | $$strInfo{LangCode} = $$tagInfo{LangCode}; | |||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||
| 760 | 3 | AddTagToTable($table, $tag, $strInfo); | |||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||
| 762 | # use strInfo ref for base key to avoid collisions | ||||||||||||||||||||||||||||||||||||||||||
| 763 | 329 | $tag = $strInfo; | |||||||||||||||||||||||||||||||||||||||||
| 764 | 329 | my $struct = \%structs; | |||||||||||||||||||||||||||||||||||||||||
| 765 | 329 | my $oldStruct = $structs{$strInfo}; | |||||||||||||||||||||||||||||||||||||||||
| 766 | # (fyi: 'lang-alt' Writable type will be valid even if tag is not pre-defined) | ||||||||||||||||||||||||||||||||||||||||||
| 767 | 329 | ▶ | my $writable = $$tagInfo{Writable} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$tagInfo->{'Writable'} || ''
MC/DC100%1/1
$tagInfo->{'Writable'} || ''
$tagInfo->{'Writable'}
Truth table100%2/2
A
A= $tagInfo->{'Writable'}
| |||||||||||||||||||||||||||||||||||||||||||
| 768 | # walk through the stored structure property information | ||||||||||||||||||||||||||||||||||||||||||
| 769 | # to rebuild this structure | ||||||||||||||||||||||||||||||||||||||||||
| 770 | 329 | my ($err, $i); | |||||||||||||||||||||||||||||||||||||||||
| 771 | 329 | for (;;) { | |||||||||||||||||||||||||||||||||||||||||
| 772 | 579 | my $index = $$prop[1]; | |||||||||||||||||||||||||||||||||||||||||
| 773 | 579 | ▶ | if ($index and not @$structProps) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$index and not @$structProps
MC/DC100%2/2
$index and not @$structProps
$index
not @$structProps
Truth table100%3/3
A and not(B)
A= $indexB= not @$structProps
| |||||||||||||||||||||||||||||||||||||||||||
| 774 | # ignore this list if it is a simple lang-alt tag | ||||||||||||||||||||||||||||||||||||||||||
| 775 | 216 | ▶ | if ($writable eq 'lang-alt') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 776 | 90 | pop @$prop; # remove lang-alt index | |||||||||||||||||||||||||||||||||||||||||
| 777 | 90 | ▶ | undef $index if @$prop < 2; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 778 | } | ||||||||||||||||||||||||||||||||||||||||||
| 779 | # add language code if necessary | ||||||||||||||||||||||||||||||||||||||||||
| 780 | 216 | ▶ | if ($$tagInfo{LangCode} and not ref $tag) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$tagInfo->{"LangCode"} and not ref $tag
MC/DC100%2/2
$tagInfo->{"LangCode"} and not ref $tag
$tagInfo->{"LangCode"}
not ref $tag
Truth table100%3/3
A and not(B)
A= $tagInfo->{"LangCode"}B= not ref $tag
| |||||||||||||||||||||||||||||||||||||||||||
| 781 | 24 | $tag = $tag . '-' . $$tagInfo{LangCode}; | |||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||
| 784 | 579 | my $nextStruct = $$struct{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 785 | 579 | ▶ | if (defined $index) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 786 | # the field is a list | ||||||||||||||||||||||||||||||||||||||||||
| 787 | 276 | $index = substr $index, 1; # remove digit count | |||||||||||||||||||||||||||||||||||||||||
| 788 | 276 | ▶ | if ($nextStruct) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 789 | 160 | ▶ | ref $nextStruct eq 'ARRAY' or $err = 2, last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 790 | 160 | $struct = $nextStruct; | |||||||||||||||||||||||||||||||||||||||||
| 791 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 792 | 116 | $struct = $$struct{$tag} = [ ]; | |||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||
| 794 | 276 | $nextStruct = $$struct[$index]; | |||||||||||||||||||||||||||||||||||||||||
| 795 | # descend into multi-dimensional lists | ||||||||||||||||||||||||||||||||||||||||||
| 796 | 276 | ▶ | for ($i=2; $$prop[$i]; ++$i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 797 | 0 | ▶ | if ($nextStruct) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 798 | 0 | ▶ | ref $nextStruct eq 'ARRAY' or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 0 | $struct = $nextStruct; | |||||||||||||||||||||||||||||||||||||||||
| 800 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 801 | 0 | $lists{$struct} = $struct; | |||||||||||||||||||||||||||||||||||||||||
| 802 | 0 | $struct = $$struct[$index] = [ ]; | |||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | $nextStruct = $$struct[$index]; | |||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | $index = substr $$prop[$i], 1; | |||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||
| 807 | 276 | ▶ | if (ref $nextStruct eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 808 | 61 | $struct = $nextStruct; # continue building sub-structure | |||||||||||||||||||||||||||||||||||||||||
| 809 | } elsif (@$structProps) { | ||||||||||||||||||||||||||||||||||||||||||
| 810 | 66 | $lists{$struct} = $struct; | |||||||||||||||||||||||||||||||||||||||||
| 811 | 66 | $struct = $$struct[$index] = { }; | |||||||||||||||||||||||||||||||||||||||||
| 812 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 813 | 149 | $lists{$struct} = $struct; | |||||||||||||||||||||||||||||||||||||||||
| 814 | 149 | $$struct[$index] = $$valueHash{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 815 | 149 | last; | |||||||||||||||||||||||||||||||||||||||||
| 816 | } | ||||||||||||||||||||||||||||||||||||||||||
| 817 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 818 | 303 | ▶ | if ($nextStruct) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 819 | 93 | ▶ | ref $nextStruct eq 'HASH' or $err = 3, last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | 93 | $struct = $nextStruct; | |||||||||||||||||||||||||||||||||||||||||
| 821 | } elsif (@$structProps) { | ||||||||||||||||||||||||||||||||||||||||||
| 822 | 30 | $struct = $$struct{$tag} = { }; | |||||||||||||||||||||||||||||||||||||||||
| 823 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 824 | 180 | $$struct{$tag} = $$valueHash{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 825 | 180 | last; | |||||||||||||||||||||||||||||||||||||||||
| 826 | } | ||||||||||||||||||||||||||||||||||||||||||
| 827 | } | ||||||||||||||||||||||||||||||||||||||||||
| 828 | 250 | ▶ | $prop = shift @$structProps or last; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 829 | 250 | $tag = $$prop[0]; | |||||||||||||||||||||||||||||||||||||||||
| 830 | 250 | ▶ | if ($tag =~ /(.+):(.+)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 831 | # tag in variable-namespace tables will have a leading | ||||||||||||||||||||||||||||||||||||||||||
| 832 | # XMP namespace on the tag name. In this case, add | ||||||||||||||||||||||||||||||||||||||||||
| 833 | # the corresponding group1 name to the tag ID. | ||||||||||||||||||||||||||||||||||||||||||
| 834 | 17 | my ($ns, $name) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 835 | 17 | ▶ | $ns = $stdXlatNS{$ns} if $stdXlatNS{$ns}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 836 | 17 | $tag = "XMP-$ns:" . ucfirst $name; | |||||||||||||||||||||||||||||||||||||||||
| 837 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 838 | 233 | $tag = ucfirst $tag; | |||||||||||||||||||||||||||||||||||||||||
| 839 | } | ||||||||||||||||||||||||||||||||||||||||||
| 840 | } | ||||||||||||||||||||||||||||||||||||||||||
| 841 | 329 | ▶ | if ($err) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 842 | # this may happen if we have a structural error in the XMP | ||||||||||||||||||||||||||||||||||||||||||
| 843 | # (like an improperly contained list for example) | ||||||||||||||||||||||||||||||||||||||||||
| 844 | 0 | ▶ | unless ($$et{NO_STRUCT_WARN}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | ▶ | my $ns = $$tagInfo{Namespace} || $$tagInfo{Table}{NAMESPACE} || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/5
$tagInfo->{'Namespace'} || $tagInfo->{'Table'}{'NAMESPACE'} || ''
$tagInfo->{"Namespace"} or $tagInfo->{"Table"}{"NAMESPACE"}
MC/DC0%0/2
$tagInfo->{'Namespace'} || $tagInfo->{'Table'}{'NAMESPACE'} || ''
$tagInfo->{"Namespace"}
$tagInfo->{"Table"}{"NAMESPACE"}
Truth table0%0/3
A or B
A= $tagInfo->{"Namespace"}B= $tagInfo->{"Table"}{"NAMESPACE"}
| |||||||||||||||||||||||||||||||||||||||||||
| 846 | 0 | $et->Warn("Error $err placing $ns:$$tagInfo{TagID} in structure or list", 1); | |||||||||||||||||||||||||||||||||||||||||
| 847 | } | ||||||||||||||||||||||||||||||||||||||||||
| 848 | 0 | ▶ | delete $structs{$strInfo} unless $oldStruct; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 849 | } elsif ($tagInfo eq $strInfo) { | ||||||||||||||||||||||||||||||||||||||||||
| 850 | # just a regular list tag (or an empty structure) | ||||||||||||||||||||||||||||||||||||||||||
| 851 | 178 | ▶ | if ($oldStruct) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 852 | # keep tag with lowest numbered key (well, not exactly, since | ||||||||||||||||||||||||||||||||||||||||||
| 853 | # "Tag (10)" is lt "Tag (2)", but at least "Tag" is lt | ||||||||||||||||||||||||||||||||||||||||||
| 854 | # everything else, and this is really what we care about) | ||||||||||||||||||||||||||||||||||||||||||
| 855 | 75 | my $k = $listKeys{$oldStruct}; | |||||||||||||||||||||||||||||||||||||||||
| 856 | 75 | ▶ | if ($k) { # ($k will be undef for an empty structure) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 857 | 75 | ▶ | if ($k lt $key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 858 | # keep lowest file order | ||||||||||||||||||||||||||||||||||||||||||
| 859 | 49 | ▶ | $$fileOrder{$k} = $$fileOrder{$key} if $$fileOrder{$k} > $$fileOrder{$key}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 860 | 49 | $et->DeleteTag($key); | |||||||||||||||||||||||||||||||||||||||||
| 861 | 49 | next; | |||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||
| 863 | 26 | ▶ | $$fileOrder{$key} = $$fileOrder{$k} if $$fileOrder{$key} > $$fileOrder{$k}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 864 | 26 | $et->DeleteTag($k); # remove tag with greater copy number | |||||||||||||||||||||||||||||||||||||||||
| 865 | } | ||||||||||||||||||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||||||||||||||||
| 867 | # replace existing value with new list | ||||||||||||||||||||||||||||||||||||||||||
| 868 | 129 | $$valueHash{$key} = $structs{$strInfo}; | |||||||||||||||||||||||||||||||||||||||||
| 869 | 129 | $listKeys{$structs{$strInfo}} = $key; # save key for this list tag | |||||||||||||||||||||||||||||||||||||||||
| 870 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 871 | # save strInfo ref and file order | ||||||||||||||||||||||||||||||||||||||||||
| 872 | 151 | ▶ | if ($var{$strInfo}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 873 | # set file order to just before the first associated flattened tag | ||||||||||||||||||||||||||||||||||||||||||
| 874 | 104 | ▶ | if ($var{$strInfo}[1] > $$fileOrder{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 875 | 33 | $var{$strInfo}[1] = $$fileOrder{$key} - 0.5; | |||||||||||||||||||||||||||||||||||||||||
| 876 | } | ||||||||||||||||||||||||||||||||||||||||||
| 877 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 878 | 47 | $var{$strInfo} = [ $strInfo, $$fileOrder{$key} - 0.5 ]; | |||||||||||||||||||||||||||||||||||||||||
| 879 | } | ||||||||||||||||||||||||||||||||||||||||||
| 880 | # preserve original flattened tags if requested | ||||||||||||||||||||||||||||||||||||||||||
| 881 | 151 | ▶ | if ($keepFlat) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 882 | 81 | my $extra = $$tagExtra{$key}; | |||||||||||||||||||||||||||||||||||||||||
| 883 | # restore list behaviour of this flattened tag | ||||||||||||||||||||||||||||||||||||||||||
| 884 | 81 | ▶ | if ($$extra{NoList}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 885 | 6 | $$valueHash{$key} = $$extra{NoList}; | |||||||||||||||||||||||||||||||||||||||||
| 886 | 6 | delete $$extra{NoList}; | |||||||||||||||||||||||||||||||||||||||||
| 887 | } elsif ($$extra{NoListDel}) { | ||||||||||||||||||||||||||||||||||||||||||
| 888 | # delete this tag since its value was included another list | ||||||||||||||||||||||||||||||||||||||||||
| 889 | 8 | $et->DeleteTag($key); | |||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||
| 891 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 892 | 70 | $et->DeleteTag($key); # delete the flattened tag | |||||||||||||||||||||||||||||||||||||||||
| 893 | } | ||||||||||||||||||||||||||||||||||||||||||
| 894 | } | ||||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||
| 896 | # fill in undefined items in lists. In theory, undefined list items should | ||||||||||||||||||||||||||||||||||||||||||
| 897 | # be fine, but in practice the calling code may not check for this (and | ||||||||||||||||||||||||||||||||||||||||||
| 898 | # historically this wasn't necessary, so do this for backward compatibility) | ||||||||||||||||||||||||||||||||||||||||||
| 899 | 28 | foreach $si (keys %lists) { | |||||||||||||||||||||||||||||||||||||||||
| 900 | 116 | ▶ | defined $_ or $_ = '' foreach @{$lists{$si}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 901 | } | ||||||||||||||||||||||||||||||||||||||||||
| 902 | # make a list of all new structures we generated | ||||||||||||||||||||||||||||||||||||||||||
| 903 | 28 | ▶ | $var{$_} and push @siList, $_ foreach keys %structs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 904 | # save new structures in the same order they were read from file | ||||||||||||||||||||||||||||||||||||||||||
| 905 | 28 | foreach $si (sort { $var{$a}[1] <=> $var{$b}[1] } @siList) { | |||||||||||||||||||||||||||||||||||||||||
| 906 | # test to see if a tag for this structure has already been generated | ||||||||||||||||||||||||||||||||||||||||||
| 907 | # (this could happen only if one of the structures in a list was empty) | ||||||||||||||||||||||||||||||||||||||||||
| 908 | 47 | $key = $var{$si}[0]{Name}; | |||||||||||||||||||||||||||||||||||||||||
| 909 | 47 | my $found; | |||||||||||||||||||||||||||||||||||||||||
| 910 | 47 | ▶ | if ($$valueHash{$key}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 911 | 0 | my @keys = grep /^$key( \(\d+\))?$/, keys %$valueHash; | |||||||||||||||||||||||||||||||||||||||||
| 912 | 0 | foreach $key (@keys) { | |||||||||||||||||||||||||||||||||||||||||
| 913 | 0 | ▶ | next unless $$valueHash{$key} eq $structs{$si}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 914 | 0 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||
| 915 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 916 | } | ||||||||||||||||||||||||||||||||||||||||||
| 917 | } | ||||||||||||||||||||||||||||||||||||||||||
| 918 | 47 | ▶ | unless ($found) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 919 | # otherwise, generate a new tag for this structure | ||||||||||||||||||||||||||||||||||||||||||
| 920 | 47 | $key = $et->FoundTag($var{$si}[0], ''); | |||||||||||||||||||||||||||||||||||||||||
| 921 | 47 | $$valueHash{$key} = $structs{$si}; | |||||||||||||||||||||||||||||||||||||||||
| 922 | } | ||||||||||||||||||||||||||||||||||||||||||
| 923 | 47 | $$fileOrder{$key} = $var{$si}[1]; | |||||||||||||||||||||||||||||||||||||||||
| 924 | } | ||||||||||||||||||||||||||||||||||||||||||
| 925 | } | ||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||
| 928 | 15 | 1; #end | |||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||
| 930 | __END__ | ||||||||||||||||||||||||||||||||||||||||||