lib/File/Information/Deep.pm

filter: Statementstmt 8.7% 52 / 598 Branchbran 0.0% 0 / 324 Conditioncond 0.0% 0 / 149 MC/DCmcdc 0.0% 0 / 80 Subroutinesub 20.5% 7 / 34 Podpod 100% 2 / 2 totaltotal 5.1% 61 / 1187 CC 239 SCAR 55.6
CC
239
Cov
5%
_load_vmv0
756.0
_load_audio_scan
506.0
_load_vmv0__load_chunks
420.0
CRAP 260.0
« lib/File/Information.pm ↑ Summary lib/File/Information/Filesystem.pm »
1 # Copyright (c) 2025 Philipp Schafft <lion@cpan.org>
2  
3 # licensed under Artistic License 2.0 (see LICENSE file)
4  
5 # ABSTRACT: generic module for extracting information from filesystems
6  
7  
8 package File::Information::Deep;
9  
10 3 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use parent 'File::Information::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Fcntl qw(SEEK_SET SEEK_CUR);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 our $VERSION = v0.17;
21  
22 3 my %_PNG_colour_types = ( # namespace: 4c11d438-f6f3-417f-85e3-e56e46851dae
23 0 => {ise => 'a3934b85-5bec-5cd7-a571-727e4cecfcb1', displayname => 'Greyscale'},
24 2 => {ise => '56262598-1d35-566d-b9a3-0e752d58b8ce', displayname => 'Truecolor'},
25 3 => {ise => '67f61b65-4978-510b-b318-247da7934837', displayname => 'Indexed-color'},
26 4 => {ise => 'cbdafa4e-1cb8-59a9-b6ec-b7a1bef3fcd4', displayname => 'Greyscale with alpha'},
27 6 => {ise => 'c6ef9ba0-3b7f-5248-a4f4-18e39c14d7b3', displayname => 'Truecolor with alpha'},
28 );
29  
30 3 my %_PNG_filter_method = ( # namespace: 06f15860-8191-41f5-881c-a465be563089
31 0 => {ise => 'b7a197cb-2eee-517f-ae57-8e299d1a92e9', displayname => 'None'},
32 1 => {ise => 'c194fcce-c957-5436-861f-09af8526fed8', displayname => 'Sub'},
33 2 => {ise => 'fe14ef2d-4098-5a7e-81a0-88beae0e1e65', displayname => 'Up'},
34 3 => {ise => 'b0df25b4-b1fb-52cc-a6be-162440bd9628', displayname => 'Average'},
35 4 => {ise => '974cf00a-c2e2-5d08-b1da-08169e09b173', displayname => 'Paeth'},
36 );
37  
38 3 my %_PNG_compression_method = ( # namespace: b2b8b4bf-3b0f-4037-9bbc-96e6b53ae73d
39 0 => {ise => 'f47c8ff3-5218-555d-bf89-ba30706c29e1', displayname => 'deflate'},
40 );
41  
42 3 my %_vmv0_section_types = (
43 1 => {ise => 'bc0dc85a-8c72-5ab6-a60b-377fdf76f678', displayname => 'init'},
44 2 => {ise => '18b7bfe0-5e3a-5fe4-ad69-a317e6b2445c', displayname => 'header'},
45 3 => {ise => '5460c878-23d6-56b9-8600-9375d76fefc5', displayname => 'rodata'},
46 4 => {ise => '0520d8d6-3a85-56d2-ae2b-77c517cff2ce', displayname => 'text'},
47 5 => {ise => '95f7f330-a72d-5e0b-ab0f-d46f37edbc9a', displayname => 'trailer'},
48 6 => {ise => '9bbc79eb-5a31-5797-8a05-56e58c530289', displayname => 'resources'},
49 );
50  
51 3 my %_flac_metadata_blocks = (
52 0 => {ise => '92fd400d-4c47-5db2-b237-f3a0baf5343b', displayname => 'Streaminfo'},
53 1 => {ise => 'e54c4b6f-b427-56d1-af10-dccf2aad38d2', displayname => 'Padding'},
54 2 => {ise => 'c6e38060-7aa9-5d2c-b657-c9384d45dbe1', displayname => 'Application'},
55 3 => {ise => 'f0aa49be-a79a-5fb6-aa78-05a3ee902ce6', displayname => 'Seek table'},
56 4 => {ise => 'bdf21d34-8843-5f1e-8a5f-776c151991cd', displayname => 'Vorbis comment'},
57 5 => {ise => '4c8656e4-a204-55d0-a5d9-a227200f1fce', displayname => 'Cuesheet'},
58 6 => {ise => '97d2ac83-ab79-5715-8115-096a6ab05189', displayname => 'Picture'},
59 );
60  
61 # RIFF/WAVE codecs:
62 3 my @_riff_wave_codecs = (
63 {ise => '00000001-0000-0010-8000-00aa00389b71', displayname => 'PCM'},
64 {ise => '00000003-0000-0010-8000-00aa00389b71', displayname => 'IEEE FLOAT'},
65 {ise => '00000006-0000-0010-8000-00aa00389b71', displayname => 'ALAW'},
66 {ise => '00000007-0000-0010-8000-00aa00389b71', displayname => 'MULAW'},
67 {ise => '00000050-0000-0010-8000-00aa00389b71', displayname => 'MPEG-1 Layer I, II'},
68 {ise => '00000055-0000-0010-8000-00aa00389b71', displayname => 'MPEG-1 Layer III (MP3)'},
69 );
70  
71 # Extra tags that do not belong into one of the other lists.
72 3 my %_wk = (
73 '.section' => {ise => 'dad2de0d-9711-5b57-9a31-562122d756ba', displayname => '.section'},
74 '.chunk' => {ise => 'bff479fa-a818-58dc-b5df-539852fa8b80', displayname => '.chunk'},
75 'flac-metadata-block' => {ise => '71edae67-d10e-48d3-ab69-4dfc88e9081c', displayname => 'flac-metadata-block'},
76 'riff-master-chunk' => {ise => '66f903f6-e2de-4871-916e-e82f68d100a3', displayname => 'riff-master-chunk'},
77 'riff-slave-chunk' => {ise => '07ef1e35-b1c1-43c8-bb8b-ffd24c759bcb', displayname => 'riff-slave-chunk'},
78 'mono' => {ise => 'a7747b62-cbb1-4912-976d-9840ce230d78', displayname => 'mono'},
79 #'stereo' => {ise => 'e9302902-8a56-490f-bcbe-60bdc2ce3ea9', displayname => 'stereo'}, # not yet used.
80 'l-r-stereo' => {ise => '0687c0ed-1138-4265-97bc-78b448292647', displayname => 'L-R-stereo'},
81 );
82  
83 3 my %_properties = (
84 chunk_inner_type => {},
85 pdf_version => {loader => \&_load_pdf},
86 pdf_pages => {loader => \&_load_pdf},
87 odf_keywords => {loader => \&_load_odf},
88 data_uriid_barcodes => {loader => \&_load_barcodes, rawtype => 'Data::URIID::Barcode'},
89 vmv0_filesize => {loader => \&_load_vmv0},
90 vmv0_section_pointer => {loader => \&_load_vmv0},
91 vmv0_section => {loader => \&_load_vmv0, rawtype => 'File::Information::Chunk'},
92 vmv0_minimum_handles => {loader => \&_load_vmv0},
93 vmv0_minimum_ram => {loader => \&_load_vmv0},
94 vmv0_boundary_text => {loader => \&_load_vmv0},
95 vmv0_boundary_load => {loader => \&_load_vmv0},
96 png_ihdr_width => {loader => \&_load_png},
97 png_ihdr_height => {loader => \&_load_png},
98 png_ihdr_bit_depth => {loader => \&_load_png},
99 png_ihdr_color_type => {loader => \&_load_png},
100 png_ihdr_compression_method => {loader => \&_load_png},
101 png_ihdr_filter_method => {loader => \&_load_png},
102 png_ihdr_interlace_method => {loader => \&_load_png},
103 gif_screen_width => {loader => \&_load_gif},
104 gif_screen_height => {loader => \&_load_gif},
105 gpl_palette_name => {loader => \&_load_gpl},
106 gpl_palette_columns => {loader => \&_load_gpl},
107 gpl_palette_colours => {loader => \&_load_gpl},
108 rgbtxt_palette_colours => {loader => \&_load_rgbtxt},
109 libpng_ihdr_width => {loader => \&_load_libpng},
110 libpng_ihdr_height => {loader => \&_load_libpng},
111 libpng_ihdr_color_type => {loader => \&_load_libpng},
112 libpng_plte_colours => {loader => \&_load_libpng},
113 riff_format => {loader => \&_load_riff, rawtype => 'binary'},
114 riff_root_chunk => {loader => \&_load_riff, rawtype => 'File::Information::Chunk'},
115 riff_wave_fmt_format => {loader => \&_load_riff_chunks},
116 riff_wave_fmt_channels => {loader => \&_load_riff_chunks},
117 riff_wave_fmt_frequency => {loader => \&_load_riff_chunks},
118 riff_wave_fmt_bytes_per_second => {loader => \&_load_riff_chunks},
119 riff_wave_fmt_bytes_per_block => {loader => \&_load_riff_chunks},
120 riff_wave_fmt_bits_per_sample => {loader => \&_load_riff_chunks},
121 riff_wave_fact_frames => {loader => \&_load_riff_chunks},
122 flac_file_metadata => {loader => \&_load_flac, rawtype => 'File::Information::Chunk'},
123 flac_streaminfo_min_block_size => {loader => \&_load_flac_metadata_blocks},
124 flac_streaminfo_max_block_size => {loader => \&_load_flac_metadata_blocks},
125 flac_streaminfo_min_frame_size => {loader => \&_load_flac_metadata_blocks},
126 flac_streaminfo_max_frame_size => {loader => \&_load_flac_metadata_blocks},
127 flac_streaminfo_sample_rate => {loader => \&_load_flac_metadata_blocks},
128 flac_streaminfo_channels => {loader => \&_load_flac_metadata_blocks},
129 flac_streaminfo_bits => {loader => \&_load_flac_metadata_blocks},
130 flac_streaminfo_total_samples => {loader => \&_load_flac_metadata_blocks},
131 flac_streaminfo_md5_checksum => {loader => \&_load_flac_metadata_blocks},
132 flac_vorbiscomment_vendor => {loader => \&_load_flac_metadata_blocks},
133 );
134  
135 3 my %_vmv0_code_P1_info = (
136 0 => 'vmv0_filesize',
137 2 => 'vmv0_minimum_handles',
138 3 => 'vmv0_minimum_ram',
139 4 => 'vmv0_boundary_text',
140 5 => 'vmv0_boundary_load',
141 );
142  
143 3 my @_odf_medadata_keys = qw(title description subject creator language initial_creator editing_cycles editing_duration generator creation_date date);
144 3 my @_image_info_keys = qw(height width file_media_type file_ext color_type resolution SamplesPerPixel BitsPerSample Comment Interlace Compression Gamma LastModificationTime);
145 3 my @_image_extra_keys = qw(Thumb::URI Thumb::Image::Width Thumb::Image::Height Thumb::MTime Software);
146 3 my @_dynamic_loaders = (\&_load_odf, \&_load_audio_scan, \&_load_flac_metadata_blocks);
147  
148 3 my %_audio_scan_tags = (
149 vorbiscomments => {
150 title => 'title',
151 },
152 riffwave => {
153 title => 'inam',
154 },
155 id3 => {
156 title => 'tit2',
157 },
158 );
159  
160 3 foreach my $keyword (qw(Author CreationDate ModDate Creator Producer Title Subject Keywords)) {
161 24 $_properties{'pdf_info_'.lc($keyword)} = {loader => \&_load_pdf};
162 }
163 3 foreach my $keyword (qw(CreationDate ModDate)) {
164 6 $_properties{'pdf_info_'.lc($keyword)}{parsing} = 'pdf_date';
165 }
166  
167 3 foreach my $key (@_odf_medadata_keys) {
168 33 $_properties{'odf_info_'.$key} = {loader => \&_load_odf};
169 }
170 3 foreach my $key (qw(creation_date date)) {
171 6 $_properties{'odf_info_'.$key}{parsing} = 'iso8601';
172 }
173  
174 3 foreach my $key (@_image_info_keys) {
175 39 $_properties{'image_info_'.lc($key)} = {loader => \&_load_image_info};
176 }
177 3 foreach my $key (@_image_extra_keys) {
178 15 $_properties{'image_info_extra_'.lc($key =~ s/::/_/r)} = {loader => \&_load_image_info};
179 }
180 3 $_properties{image_info_extra_thumb_mtime}{rawtype} = 'unixts';
181 3 $_properties{image_info_extra_thumb_uri}{rawtype} = 'uri';
182  
183  
184 # Register well known:
185 3 foreach my $value (
186 values(%_PNG_colour_types),
187 values(%_PNG_filter_method),
188 values(%_PNG_compression_method),
189 values(%_vmv0_section_types),
190 values(%_flac_metadata_blocks),
191 values(%_wk),
192 @_riff_wave_codecs,
193 ) {
194 111 Data::Identifier->new(ise => $value->{ise}, displayname => $value->{displayname})->register;
195 }
196  
197  
198 #@returns File::Information::Base
199 0 ▶sub parent {
Subroutine parent: not called CC=1 SCAR=6.9
Pod documented
200 0 my ($self) = @_;
201 0 return $self->{parent};
202 }
203  
204 # ----------------
205 0 ▶sub property_info {
Subroutine property_info: not called CC=3 SCAR=24.8
Pod documented
206 0 my ($self, @args) = @_;
207  
208 0 ▶ unless (defined $self->{_dynamic}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_dynamic"}) 0 0 0
209 0 $self->{_dynamic} = 1;
210 0 foreach my $cb (@_dynamic_loaders) {
211 0 $self->$cb('__dummy__');
212 }
213 }
214  
215 0 return $self->SUPER::property_info(@args);
216 }
217  
218 0 ▶sub _new {
Subroutine _new: not called CC=3 SCAR=24.8
219 0 my ($pkg, %opts) = @_;
220 0 my $self = $pkg->SUPER::_new(%opts, properties => \%_properties);
221 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
222 0 my $parent = $self->{parent};
223  
224 0 weaken($self->{parent});
225  
226 # copy a few critical values:
227 0 eval { $pv->{contentise} = {raw => $parent->get('contentise', lifecycle => 'current', as => 'uuid')} };
228 0 eval { $pv->{mediatype} = {raw => $parent->get('mediatype', lifecycle => 'current', as => 'mediatype')} };
229 0 eval { $pv->{chunk_inner_type} = {ise => $parent->get('chunk_inner_type', lifecycle => 'current', as => 'ise')} };
230 0 eval { $pv->{size} = {raw => $parent->get('size', lifecycle => 'current', as => 'raw')} };
231  
232 0 return $self;
233 }
234  
235 0 ▶sub _dynamic_property {
Subroutine _dynamic_property: not called CC=2 SCAR=17.9
236 0 my ($self, $prefix, $property) = @_;
237 0 my $key;
238  
239 0 $property = lc($property);
240 0 $property =~ s/::/_/g;
241 0 $property =~ s/[^a-z0-9]/_/g;
242 0 ▶ $_properties{$key = $prefix.'_'.$property} //= {};
Condition0%0/2
$_properties{$key = $prefix . '_' . $property} //= {}
l!l
00
MC/DC0%0/1
$_properties{$key = $prefix . '_' . $property} //= {}
$_properties{$key = $prefix . '_' . $property}
Truth table0%0/2
A
A= $_properties{$key = $prefix . '_' . $property}
Aresult
11
00
243  
244 0 return $key;
245 }
246  
247 0 ▶sub _check_mediatype {
Subroutine _check_mediatype: not called CC=4 SCAR=30.0
248 0 my ($self, @mediasubtypes) = @_;
249 0 my $v;
250  
251 0 ▶ return undef unless defined $self->{properties_values}{current}{mediatype}{raw};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"properties_values"}{"current"}{"mediatype"}{"raw"} 0 0 0
252  
253 0 $v = $self->{properties_values}{current}{mediatype}{raw};
254  
255 0 foreach my $mediasubtype (@mediasubtypes) {
256 0 ▶ return 1 if $v eq $mediasubtype;
Branch: 1 branch
BranchTrueFalseTotal
if $v eq $mediasubtype 0 0 0
257 }
258  
259 0 return undef;
260 }
261  
262 0 ▶sub _pdf_extract_date {
Subroutine _pdf_extract_date: not called CC=5 SCAR=34.0
263 0 my ($self, $value) = @_;
264 0 require DateTime::Format::Strptime;
265  
266 0 state $pdf_date_core_pattern = '%Y%m%d%H%M%S';
267 0 state $pdf_date_format_0 = DateTime::Format::Strptime->new('pattern' => $pdf_date_core_pattern, 'time_zone' => 'UTC');
268 0 my $dt;
269 my $core;
270 0 my $parser;
271  
272 # General format: D:YYYYMMDDHHmmSSOHH'mm'
273  
274 0 ▶ if (($core) = $value =~ /^D:([0-9]{14})Z'{0,2}$/) {
Branch: 2 branches
BranchTrueFalseTotal
if (($core) = $value =~ /^D:([0-9]{14})Z'{0,2}$/u) { } 0 0 0
elsif (() = $value =~ /^D:([0-9]{14})(\+|\-)([0-9]{2})'([0-9]{2})'$/u) { } 0 0 0
275 0 $parser = $pdf_date_format_0;
276 } elsif (my ($mycore, $tz_dir, $tz_h, $tz_m) = $value =~ /^D:([0-9]{14})(\+|\-)([0-9]{2})'([0-9]{2})'$/) {
277 0 my $tz = sprintf('%s%s%s', $tz_dir, $tz_h, $tz_m);
278 0 $core = $mycore;
279 0 $parser = DateTime::Format::Strptime->new('pattern' => $pdf_date_core_pattern, 'time_zone' => $tz);
280 }
281  
282 0 ▶ return undef unless defined($core) && defined($parser);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $core and defined $parser 0 0 0
Condition0%0/3
defined $core and defined $parser
!ll&&!rl&&r
000
MC/DC0%0/2
defined $core and defined $parser
defined $core defined $parser
Truth table0%0/3
A and B
A= defined $coreB= defined $parser
ABresult
0X0
100
111
283  
284 0 return $parser->parse_datetime($core);
285 }
286  
287 0 ▶sub _load_pdf {
Subroutine _load_pdf: not called CC=11 SCAR=48.8
288 0 my ($self, $key, %opts) = @_;
289 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
290  
291 0 ▶ return if defined $self->{_loaded_pdf};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_pdf"} 0 0 0
292 0 $self->{_loaded_pdf} = 1;
293  
294 0 ▶ return unless defined $self->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"path"} 0 0 0
295 0 ▶ return unless $self->_check_mediatype('application/pdf');
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_check_mediatype("application/pdf") 0 0 0
296  
297 # Check for module;
298 0 ▶ if (eval {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require PDF::API2; "PDF::API2"->VERSION("2.044"); "PDF::API2"->import; 1 } }) 0 0 0
299 0 require PDF::API2;
300 0 PDF::API2->VERSION(2.044);
301 0 PDF::API2->import();
302 0 1;
303 }) {
304 0 my $pdf = PDF::API2->open($self->{path});
305 0 my %info = $pdf->info_metadata();
306  
307 0 $pv->{pdf_version} = {raw => $pdf->version};
308 0 $pv->{pdf_pages} = {raw => $pdf->page_count};
309  
310 0 foreach my $key (keys %info) {
311 0 ▶ if (defined(my $value = $info{$key})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $value = $info{$key})) 0 0 0
312 0 my $pv_key = 'pdf_info_'.lc($key);
313  
314 0 ▶ $value = $self->_pdf_extract_date($value) if ($_properties{$pv_key}{parsing} // '') eq 'pdf_date';
Branch: 1 branch
BranchTrueFalseTotal
if ($_properties{$pv_key}{"parsing"} // "") eq "pdf_date" 0 0 0
Condition0%0/2
$_properties{$pv_key}{"parsing"} // ""
l!l
00
MC/DC0%0/1
$_properties{$pv_key}{"parsing"} // ""
$_properties{$pv_key}{"parsing"}
Truth table0%0/2
A
A= $_properties{$pv_key}{"parsing"}
Aresult
11
00
315 0 $pv->{$pv_key} = {raw => $value};
316 }
317 }
318  
319 0 $pdf->close;
320 }
321 }
322  
323 0 ▶sub _load_odf {
Subroutine _load_odf: not called CC=17 SCAR=57.2
324 0 my ($self, $key, %opts) = @_;
325 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
326  
327 0 ▶ return if defined $self->{_loaded_odf};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_odf"} 0 0 0
328 0 $self->{_loaded_odf} = 1;
329  
330 0 ▶ return unless defined $self->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"path"} 0 0 0
331 0 ▶ return unless $self->_check_mediatype(qw(application/vnd.oasis.opendocument.text));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_check_mediatype("application/vnd.oasis.opendocument.text") 0 0 0
332  
333 # Check for module;
334 0 ▶ if (eval {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require OpenOffice::OODoc; require DateTime::Format::ISO8601; "OpenOffice::OODoc"->import; "DateTime::Format::ISO8601"->import; 1 } }) 0 0 0
335 0 require OpenOffice::OODoc;
336 0 require DateTime::Format::ISO8601;
337 0 OpenOffice::OODoc->import();
338 0 DateTime::Format::ISO8601->import();
339 0 1;
340 }) {
341 0 my $document = odfDocument(file => $self->{path});
342 0 my $meta = odfMeta(file => $document);
343  
344 0 foreach my $key (@_odf_medadata_keys) {
345 0 my $func = $meta->can($key);
346 0 my $value = $meta->$func();
347 0 my $pv_key = 'odf_info_'.$key;
348 0 ▶ next unless defined($value) && length($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
349  
350 0 ▶ $value = DateTime::Format::ISO8601->parse_datetime($value) if ($_properties{$pv_key}{parsing} // '') eq 'iso8601';
Branch: 1 branch
BranchTrueFalseTotal
if ($_properties{$pv_key}{"parsing"} // "") eq "iso8601" 0 0 0
Condition0%0/2
$_properties{$pv_key}{"parsing"} // ""
l!l
00
MC/DC0%0/1
$_properties{$pv_key}{"parsing"} // ""
$_properties{$pv_key}{"parsing"}
Truth table0%0/2
A
A= $_properties{$pv_key}{"parsing"}
Aresult
11
00
351  
352 0 $pv->{$pv_key} = {raw => $value};
353 }
354  
355 0 $pv->{odf_keywords} = [map {{raw => $_}} $meta->keywords];
356 0 ▶ delete $pv->{odf_keywords} unless scalar @{$pv->{odf_keywords}};
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @{$pv->{"odf_keywords"};} 0 0 0
357  
358 {
359 0 my %stats = $meta->statistic;
360 0 foreach my $key (keys %stats) {
361 0 my $pv_key = $self->_dynamic_property(odf_stats => $key);
362 0 my $value = $stats{$key};
363 0 ▶ next unless defined($value) && length($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
364 0 $pv->{$pv_key} = {raw => $value};
365 }
366 }
367  
368 0 foreach my $el ($meta->getUserPropertyElements) {
369 0 my $pv_key = $self->_dynamic_property(odf_user_properties => $el->att('meta:name'));
370 0 my $value = $el->text;
371 0 $pv->{$pv_key} = {raw => $value};
372 }
373 }
374 }
375  
376 0 ▶sub _load_vmv0_decode_opcode {
Subroutine _load_vmv0_decode_opcode: not called CC=1 SCAR=6.9
377 0 my ($self, $in) = @_;
378 0 my ($op0, $op1) = unpack('CC', $in);
379 0 my $code = ($op0 & 0370) >> 3;
380 0 my $P = ($op0 & 0007) >> 0;
381 0 my $codeX = ($op1 & 0300) >> 6;
382 0 my $S = ($op1 & 0070) >> 3;
383 0 my $T = ($op1 & 0007) >> 0;
384  
385 0 return {code => $code, P => $P, codeX => $codeX, S => $S, T => $T, first => $op0, second => $op1};
386 }
387  
388 0 ▶sub _load_vmv0__load_chunks {
Subroutine _load_vmv0__load_chunks: not called CC=20 SCAR=60.4
389 0 my ($self, %opts) = @_;
390 0 my $fh = delete $opts{fh};
391 0 my $start = delete $opts{start};
392 0 my @res;
393  
394 0 ▶ return undef unless $fh;
Branch: 1 branch
BranchTrueFalseTotal
unless $fh 0 0 0
395  
396 0 while (1) {
397 0 ▶ $fh->seek($start, SEEK_SET) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$fh->seek($start, 0) or die $! 0 0 0
398 0 ▶ if (read($fh, my $in, 2) != 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($fh, my $in, 2) != 2) { } 0 0 0
399 0 last;
400 } else {
401 0 my $opcode = $self->_load_vmv0_decode_opcode($in);
402 0 my $opcode_length = 2;
403 0 my $outer_length;
404 my $inner_offset;
405 0 my $length;
406 0 my %new_opts = %opts;
407 0 my $flags;
408 my $type;
409 0 my $identifier;
410  
411 0 ▶ last unless $opcode->{first} == 6 && $opcode->{codeX} == 0 && $opcode->{S} && $opcode->{T} < 4;
Branch: 1 branch
BranchTrueFalseTotal
unless $opcode->{"first"} == 6 and $opcode->{"codeX"} == 0 and $opcode->{"S"} and $opcode->{"T"} < 4 0 0 0
Condition0%0/9
$opcode->{"first"} == 6 and $opcode->{"codeX"} == 0 and $opcode->{"S"} and $opcode->{"T"} < 4
!ll&&!rl&&r
000
$opcode->{"first"} == 6 and $opcode->{"codeX"} == 0 and $opcode->{"S"}
!ll&&!rl&&r
000
$opcode->{"first"} == 6 and $opcode->{"codeX"} == 0
!ll&&!rl&&r
000
MC/DC0%0/4
$opcode->{"first"} == 6 and $opcode->{"codeX"} == 0 and $opcode->{"S"} and $opcode->{"T"} < 4
$opcode->{"first"} == 6 $opcode->{"codeX"} == 0 $opcode->{"S"} $opcode->{"T"} < 4
Truth table0%0/5
A and B and C and D
A= $opcode->{"first"} == 6B= $opcode->{"codeX"} == 0C= $opcode->{"S"}D= $opcode->{"T"} < 4
ABCDresult
0XXX0
10XX0
110X0
11100
11111
412  
413 # Read length:
414 0 ▶ if ($opcode->{T} == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opcode->{'T'} == 1) { } 0 0 0
elsif ($opcode->{'T'} == 2) { } 0 0 0
415 0 ▶ last unless read($fh, $in, 2) == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless read($fh, $in, 2) == 2 0 0 0
416 0 $length = unpack('n', $in) * 2;
417 0 $opcode_length += 2;
418 } elsif ($opcode->{T} == 2) {
419 0 ▶ last unless read($fh, $in, 4) == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless read($fh, $in, 4) == 4 0 0 0
420 0 $length = unpack('N', $in) * 2;
421 0 $opcode_length += 4;
422 }
423  
424 0 ▶ next unless defined $length;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $length 0 0 0
425 0 $inner_offset = $opcode_length;
426  
427 # Read flags and type:
428 0 ▶ last unless read($fh, $in, 4) == 4;
Branch: 1 branch
BranchTrueFalseTotal
unless read($fh, $in, 4) == 4 0 0 0
429 0 ($flags, $type) = unpack('nn', $in);
430 0 $inner_offset += 4;
431  
432 # Read identifier (if any):
433 0 ▶ if ($flags & 0x0002) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flags & 2) 0 0 0
434 0 ▶ last unless read($fh, $in, 2) == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless read($fh, $in, 2) == 2 0 0 0
435 0 $identifier = unpack('n', $in);
436 0 $inner_offset += 2;
437 }
438  
439 0 ▶ if (($flags & 0xC000) == 0x0000) { # SNI
Branch: 2 branches
BranchTrueFalseTotal
if (($flags & 49152) == 0) { } 0 0 0
elsif (($flags & 49152) == 16384) { } 0 0 0
440 0 $type = Data::Identifier->new('039e0bb7-5dd3-40ee-a98c-596ff6cce405' => $type);
441 } elsif (($flags & 0xC000) == 0x4000) { # SID
442 0 $type = Data::Identifier->new(sid => $type);
443 } else {
444 0 $type = undef;
445 }
446  
447 0 $outer_length = $length + $opcode_length;
448 push(@res, File::Information::Chunk->_new(%opts,
449 start => $start,
450 size => $outer_length,
451 outer_type => {ise => $_wk{'.chunk'}->{ise}},
452 0 ▶ inner_type => {raw => $type, ise => $type->ise},
Branch: 1 branch
BranchTrueFalseTotal
$flags & 1 ? : 0 0 0
453 inner_start => $start + $inner_offset,
454 inner_size => $outer_length - $inner_offset - ($flags & 0x1 ? 1 : 0),
455 ));
456  
457 0 $start += $outer_length;
458 }
459 }
460  
461 0 ▶ return undef unless scalar @res;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @res 0 0 0
462 0 return \@res;
463 }
464  
465 0 ▶sub _load_vmv0__chunk {
Subroutine _load_vmv0__chunk: not called CC=12 SCAR=50.5
466 0 my ($self, %opts) = @_;
467  
468 0 ▶ if (defined(my $fh = delete $opts{fh})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $fh = delete $opts{"fh"})) 0 0 0
469 0 ▶ $fh->seek($opts{start}, SEEK_SET) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
$fh->seek($opts{"start"}, 0) or die $! 0 0 0
470 0 ▶ if (read($fh, my $in, 2) == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($fh, my $in, 2) == 2) 0 0 0
471 0 my $opcode = $self->_load_vmv0_decode_opcode($in);
472 0 ▶ if ($opcode->{first} == 0 && $opcode->{codeX} == 0 && ($opcode->{T} & 0x4)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opcode->{"first"} == 0 and $opcode->{"codeX"} == 0 and $opcode->{"T"} & 4) 0 0 0
Condition0%0/6
$opcode->{"first"} == 0 and $opcode->{"codeX"} == 0 and $opcode->{"T"} & 4
!ll&&!rl&&r
000
$opcode->{"first"} == 0 and $opcode->{"codeX"} == 0
!ll&&!rl&&r
000
MC/DC0%0/3
$opcode->{"first"} == 0 and $opcode->{"codeX"} == 0 and $opcode->{"T"} & 4
$opcode->{"first"} == 0 $opcode->{"codeX"} == 0 $opcode->{"T"} & 4
Truth table0%0/4
A and B and C
A= $opcode->{"first"} == 0B= $opcode->{"codeX"} == 0C= $opcode->{"T"} & 4
ABCresult
0XX0
10X0
1100
1111
473 0 my $n = $opcode->{T} - 4;
474  
475 0 ▶ if ($n > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n > 0) 0 0 0
476 0 $n *= 2;
477 0 ▶ (read($fh, my $magic, $n) == $n) or croak 'IO error: Cannot read '.$n.' bytes';
Branch: 1 branch
BranchTrueFalseTotal
read($fh, my $magic, $n) == $n or croak('IO error: Cannot read ' . $n . ' bytes') 0 0 0
478 0 ▶ if (length($magic) == $n) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $magic == $n) 0 0 0
479 0 $opts{outer_magic} = {raw => $magic};
480 }
481 }
482  
483 0 my $section_type = $opcode->{S};
484 0 ▶ if ($section_type == 5 || $section_type == 6) {
Branch: 1 branch
BranchTrueFalseTotal
if ($section_type == 5 or $section_type == 6) 0 0 0
Condition0%0/3
$section_type == 5 or $section_type == 6
l!l&&r!l&&!r
000
MC/DC0%0/2
$section_type == 5 or $section_type == 6
$section_type == 5 $section_type == 6
Truth table0%0/3
A or B
A= $section_type == 5B= $section_type == 6
ABresult
1X1
011
000
485 0 $opts{subchunks} = $self->_load_vmv0__load_chunks(%opts, start => $fh->tell, fh => $fh);
486 }
487 0 $opts{outer_type} = {ise => $_wk{'.section'}->{ise}};
488 0 $opts{inner_type} = {ise => $_vmv0_section_types{$section_type}->{ise}};
489 }
490 }
491 }
492  
493 0 return File::Information::Chunk->_new(%opts);
494 }
495 0 ▶sub _load_vmv0 {
Subroutine _load_vmv0: not called CC=27 SCAR=66.3
496 0 my ($self, $key, %opts) = @_;
497 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
498  
499 0 ▶ return if defined $self->{_loaded_vmv0};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_vmv0"} 0 0 0
500 0 $self->{_loaded_vmv0} = 1;
501  
502 0 ▶ return unless $self->_check_mediatype(qw(application/vnd.sirtx.vmv0));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_check_mediatype("application/vnd.sirtx.vmv0") 0 0 0
503  
504 0 ▶ if (defined(my $inode = eval { $self->inode })) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $inode = eval { do { $self->inode } })) 0 0 0
505 0 my $data = $self->peek(wanted => 1024);
506 0 my %section_pointer;
507  
508 0 ▶ while (length($data)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data) 0 0 0
509 0 my $opcode = $self->_load_vmv0_decode_opcode(substr($data, 0, 2, ''));
510 0 my ($op0, $op1, $code, $P, $codeX, $S, $T) = $opcode->@{qw(first second code P codeX S T)};
511 0 my $extra_as_num;
512 0 my $extra_len = 0;
513 0 my $extra;
514  
515 0 ▶ last if $code != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $code != 0 0 0 0
516 0 ▶ last if $P > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $P > 2 0 0 0
517 0 ▶ last if $codeX != 0;
Branch: 1 branch
BranchTrueFalseTotal
if $codeX != 0 0 0 0
518  
519 0 ▶ last if $op0 == 0 && $codeX == 0 && $S > 2; # last on non-opcode sections
Branch: 1 branch
BranchTrueFalseTotal
if $op0 == 0 and $codeX == 0 and $S > 2 0 0 0
Condition0%0/6
$op0 == 0 and $codeX == 0 and $S > 2
!ll&&!rl&&r
000
$op0 == 0 and $codeX == 0
!ll&&!rl&&r
000
MC/DC0%0/3
$op0 == 0 and $codeX == 0 and $S > 2
$op0 == 0 $codeX == 0 $S > 2
Truth table0%0/4
A and B and C
A= $op0 == 0B= $codeX == 0C= $S > 2
ABCresult
0XX0
10X0
1100
1111
520  
521 0 $extra_len = ($T & 0x3) * 2;
522  
523 0 $extra = substr($data, 0, $extra_len, '');
524  
525 0 ▶ if ($extra_len == 0) {
Branch: 3 branches
BranchTrueFalseTotal
if ($extra_len == 0) { } 0 0 0
elsif ($extra_len == 2) { } 0 0 0
elsif ($extra_len == 4) { } 0 0 0
526 0 $extra_as_num = 0;
527 } elsif ($extra_len == 2) {
528 0 $extra_as_num = unpack('n', $extra);
529 } elsif ($extra_len == 4) {
530 0 $extra_as_num = unpack('N', $extra);
531 }
532  
533 0 ▶ if ($code == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code == 0) 0 0 0
534 0 ▶ if ($P == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($P == 1) 0 0 0
535 0 ▶ if ($codeX == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($codeX == 0) 0 0 0
536 0 ▶ if (defined $extra_as_num) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $extra_as_num) 0 0 0
537 0 ▶ if (defined(my $f = $_vmv0_code_P1_info{$S})) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined(my $f = $_vmv0_code_P1_info{$S})) { } 0 0 0
elsif ($S == 1) { } 0 0 0
538 0 $pv->{$f} = {raw => $extra_as_num*2};
539 } elsif ($S == 1) {
540 0 ▶ $section_pointer{$extra_as_num*2} //= undef;
Condition0%0/2
$section_pointer{$extra_as_num * 2} //= undef
l!l
00
MC/DC0%0/1
$section_pointer{$extra_as_num * 2} //= undef
$section_pointer{$extra_as_num * 2}
Truth table0%0/2
A
A= $section_pointer{$extra_as_num * 2}
Aresult
11
00
541 }
542 }
543 }
544 }
545 }
546  
547 #warn sprintf('[code=%u, P=%u; codeX=%u, S=%u, T=%u; extra_len=%u, extra_as_num=%s]', $code, $P, $codeX, $S, $T, $extra_len, $extra_as_num // '<undef>');
548 }
549  
550 0 ▶ if (scalar keys %section_pointer) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %section_pointer) 0 0 0
551 0 my @pointers = sort {$a <=> $b} keys %section_pointer;
552 0 my $fh = $inode->_get_fh;
553 0 my @sections;
554 my $last;
555  
556 0 $pv->{vmv0_section_pointer} = [map {{raw => $_}} @pointers];
557  
558 0 require File::Information::Chunk;
559  
560 0 foreach my $c (@pointers) {
561 0 ▶ if (defined $last) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last) 0 0 0
562 0 push(@sections, $self->_load_vmv0__chunk(instance => $self->instance, path => $self->{path}, parent => $self, inode => $inode, start => $last, end => $c, fh => $fh));
563 }
564 0 $last = $c;
565 }
566 0 ▶ if (defined $last) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $last) 0 0 0
567 0 push(@sections, $self->_load_vmv0__chunk(instance => $self->instance, path => $self->{path}, parent => $self, inode => $inode, start => $last, end => scalar($inode->get('size')), fh => $fh));
568 }
569 0 $pv->{vmv0_section} = [map {{raw => $_}} @sections];
570 }
571 }
572 }
573  
574 0 ▶sub _load_png {
Subroutine _load_png: not called CC=13 SCAR=52.0
575 0 my ($self, $key, %opts) = @_;
576 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
577  
578 0 ▶ return if defined $self->{_loaded_png};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_png"} 0 0 0
579 0 $self->{_loaded_png} = 1;
580  
581 0 ▶ return unless $self->_check_mediatype(qw(image/png));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_check_mediatype("image/png") 0 0 0
582  
583 {
584 0 my $inode = $self->inode;
585 0 my $data = $self->peek(wanted => 1024);
586  
587 0 ▶ if (substr($data, 0, 8) eq "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a") {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($data, 0, 8) eq "\211PNG\r\n\32\n") 0 0 0
588 0 ▶ if (substr($data, 8, 8) eq "\0\0\0\x0dIHDR") {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($data, 8, 8) eq "\0\0\0\rIHDR") 0 0 0
589 0 ▶ my $crc = eval {require Digest::CRC; Digest::CRC->new(type => 'crc32');} // eval { require Digest; Digest->new('CRC-32'); } // croak 'No CRC-32 support';
Condition0%0/5
(eval { do { require Digest::CRC; "Digest::CRC"->new("type", "crc32") } } // eval { do { require Digest; "Digest"->new("CRC-32") } }) // croak("No CRC-32 support")
l!l
00
eval { do { require Digest::CRC; "Digest::CRC"->new("type", "crc32") } } // eval { do { require Digest; "Digest"->new("CRC-32") } }
l!l&&r!l&&!r
000
MC/DC0%0/2
(eval { do { require Digest::CRC; "Digest::CRC"->new("type", "crc32") } } // eval { do { require Digest; "Digest"->new("CRC-32") } }) // croak("No CRC-32 support")
eval { do { require Digest::CRC; "Digest::CRC"->new("type", "crc32") } } eval { do { require Digest; "Digest"->new("CRC-32") } }
Truth table0%0/3
A // B
A= eval { do { require Digest::CRC; "Digest::CRC"->new("type", "crc32") } }B= eval { do { require Digest; "Digest"->new("CRC-32") } }
ABresult
1X1
011
000
590 0 $crc->add(substr($data, 8 + 4, 4 + 13));
591 0 ▶ if (substr($data, 16 + 13, 4) eq pack('H8', $crc->hexdigest)) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($data, 29, 4) eq pack("H8", $crc->hexdigest)) 0 0 0
592 0 my ($width, $height, $bit_depth, $color_type, $compression_method, $filter_method, $interlace_method) = unpack('NNCCCCC', substr($data, 16, 13));
593 0 $pv->{png_ihdr_width} = {raw => $width};
594 0 $pv->{png_ihdr_height} = {raw => $height};
595 0 $pv->{png_ihdr_bit_depth} = {raw => $bit_depth};
596 0 $pv->{png_ihdr_interlace_method} = {raw => $interlace_method};
597 0 ▶ if (defined(my $ct = $_PNG_colour_types{$color_type})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ct = $_PNG_colour_types{$color_type})) 0 0 0
598 0 $pv->{png_ihdr_color_type} = {raw => $color_type, ise => $ct->{ise}};
599 }
600 0 ▶ if (defined(my $fm = $_PNG_filter_method{$filter_method})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $fm = $_PNG_filter_method{$filter_method})) 0 0 0
601 0 $pv->{png_ihdr_filter_method} = {raw => $filter_method, ise => $fm->{ise}};
602 }
603 0 ▶ if (defined(my $cm = $_PNG_compression_method{$compression_method})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $cm = $_PNG_compression_method{$compression_method})) 0 0 0
604 0 $pv->{png_ihdr_compression_method} = {raw => $compression_method, ise => $cm->{ise}};
605 }
606 }
607 }
608 }
609 }
610 }
611  
612 0 ▶sub _load_gif {
Subroutine _load_gif: not called CC=8 SCAR=42.8
613 0 my ($self, $key, %opts) = @_;
614 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
615  
616 0 ▶ return if defined $self->{_loaded_gif};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_gif"} 0 0 0
617 0 $self->{_loaded_gif} = 1;
618  
619 0 ▶ return unless $self->_check_mediatype(qw(image/gif));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_check_mediatype("image/gif") 0 0 0
620  
621 {
622 0 my $inode = $self->inode;
623 0 my $data = $self->peek(wanted => 1024);
624  
625 0 ▶ if (substr($data, 0, 6) eq 'GIF89a') { # TODO: check if the following code also holds true for GIF87a
Branch: 1 branch
BranchTrueFalseTotal
if (substr($data, 0, 6) eq "GIF89a") 0 0 0
626 0 my ($width, $height) = unpack('vv', substr($data, 6, 4));
627 0 ▶ $pv->{gif_screen_width} = {raw => $width} if $width > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $width > 0 0 0 0
628 0 ▶ $pv->{gif_screen_height} = {raw => $height} if $height > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $height > 0 0 0 0
629 }
630 }
631 }
632  
633 0 ▶sub _load_gpl {
Subroutine _load_gpl: not called CC=15 SCAR=54.8
634 0 my ($self, $key, %opts) = @_;
635 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
636  
637 0 ▶ return if defined $self->{_loaded_gpl};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_gpl"} 0 0 0
638 0 $self->{_loaded_gpl} = 1;
639  
640 0 ▶ if (defined(my $inode = eval { $self->inode })) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $inode = eval { do { $self->inode } })) 0 0 0
641 0 my $data = $self->peek(wanted => 64);
642  
643 0 ▶ if ($data =~ /^GIMP Palette\r?\n/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /^GIMP Palette\r?\n/u) 0 0 0
644 0 my $fh = $inode->_get_fh;
645 0 my @colours;
646  
647 0 ▶ return unless eval { require Data::URIID::Colour; 1; };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require Data::URIID::Colour; 1 } } 0 0 0
648  
649 0 ▶ while (defined(my $line = <$fh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
650 0 $line =~ s/\r?\n$//;
651 0 $line =~ s/^\s*#.*$//;
652 0 ▶ next unless length($line);
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 0 0
653 0 ▶ if ($line eq 'GIMP Palette') {
Branch: 5 branches
BranchTrueFalseTotal
if ($line eq 'GIMP Palette') { } 0 0 0
elsif ($line =~ /^Name:\s+(\S.+)$/u) { } 0 0 0
elsif ($line =~ /^Columns:\s+([1-9][0-9]*)$/u) { } 0 0 0
elsif ($line =~ /^\s*(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)\s+(\S(?:.*\S)?)$/u) { } 0 0 0
elsif ($line =~ /^(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)$/u) { } 0 0 0
654 # magic, good, no-op
655 } elsif ($line =~ /^Name:\s+(\S.+)$/) {
656 0 $pv->{gpl_palette_name} = {raw => $1};
657 } elsif ($line =~ /^Columns:\s+([1-9][0-9]*)$/) {
658 0 $pv->{gpl_palette_columns} = {raw => int($1)};
659 } elsif ($line =~ /^\s*(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)\s+(\S(?:.*\S)?)$/) {
660 0 push(@colours, {raw => Data::URIID::Colour->new(
661 rgb => sprintf('#%02x%02x%02x', $1, $2, $3),
662 displayname => $4,
663 )});
664 } elsif ($line =~ /^(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)$/) {
665 0 push(@colours, {raw => Data::URIID::Colour->new(
666 rgb => sprintf('#%02x%02x%02x', $1, $2, $3),
667 )});
668 } else {
669 # BAD line!?
670 }
671 }
672  
673 0 ▶ $pv->{gpl_palette_colours} = \@colours if scalar @colours;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @colours 0 0 0
674 }
675 }
676 }
677  
678 0 ▶sub _load_rgbtxt {
Subroutine _load_rgbtxt: not called CC=11 SCAR=48.8
679 0 my ($self, $key, %opts) = @_;
680 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
681  
682 0 ▶ return if defined $self->{_loaded_rgbtxt};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_rgbtxt"} 0 0 0
683 0 $self->{_loaded_rgbtxt} = 1;
684  
685 0 ▶ if (defined(my $inode = eval { $self->inode })) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $inode = eval { do { $self->inode } })) 0 0 0
686 0 my $data = $self->peek(wanted => 64);
687  
688 0 ▶ if ($data =~ /^\! \$Xorg: rgb\.txt,v .+ Exp \$\r?\n/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data =~ /^\! \$Xorg: rgb\.txt,v .+ Exp \$\r?\n/u) 0 0 0
689 0 my $fh = $inode->_get_fh;
690 0 my @colours;
691  
692 0 ▶ return unless eval { require Data::URIID::Colour; 1; };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require Data::URIID::Colour; 1 } } 0 0 0
693  
694 0 ▶ while (defined(my $line = <$fh>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 0 0 0
695 0 $line =~ s/\r?\n$//;
696 0 ▶ next unless length($line);
Branch: 1 branch
BranchTrueFalseTotal
unless length $line 0 0 0
697 0 ▶ if ($line =~ /^(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)\s+(\S(?:.*\S)?)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)\s+(0|[1-9][0-9]*)\s+(\S(?:.*\S)?)$/u) { } 0 0 0
698 0 push(@colours, {raw => Data::URIID::Colour->new(
699 rgb => sprintf('#%02x%02x%02x', $1, $2, $3),
700 displayname => $4,
701 )});
702 } else {
703 # BAD line!?
704 }
705 }
706  
707 0 ▶ $pv->{rgbtxt_palette_colours} = \@colours if scalar @colours;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @colours 0 0 0
708 }
709 }
710 }
711  
712 0 ▶sub _load_image_info {
Subroutine _load_image_info: not called CC=14 SCAR=53.5
713 0 my ($self, $key, %opts) = @_;
714 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
715  
716 0 ▶ return if defined $self->{_loaded_image_info};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_image_info"} 0 0 0
717 0 $self->{_loaded_image_info} = 1;
718  
719 0 ▶ return unless defined $self->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"path"} 0 0 0
720  
721 0 foreach my $data (eval {
722 0 require Image::Info;
723 0 Image::Info->import();
724 0 Image::Info::image_info($self->{path});
725 }) {
726 0 ▶ next if defined($data->{error}) && length($data->{error});
Branch: 1 branch
BranchTrueFalseTotal
if defined $data->{"error"} and length $data->{"error"} 0 0 0
Condition0%0/3
defined $data->{"error"} and length $data->{"error"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $data->{"error"} and length $data->{"error"}
defined $data->{"error"} length $data->{"error"}
Truth table0%0/3
A and B
A= defined $data->{"error"}B= length $data->{"error"}
ABresult
0X0
100
111
727  
728 0 foreach my $key (@_image_info_keys) {
729 0 my $pv_key = 'image_info_'.lc($key);
730 0 my $value = delete $data->{$key};
731  
732 0 ▶ next unless defined($value) && length($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
733  
734 0 $pv->{$pv_key} = {raw => $value};
735 }
736 0 foreach my $key (@_image_extra_keys) {
737 0 my $pv_key = 'image_info_extra_'.lc($key =~ s/::/_/r);
738 0 my $value = delete $data->{$key};
739  
740 0 ▶ next unless defined($value) && length($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
741  
742 0 $pv->{$pv_key} = {raw => $value};
743 }
744 }
745 }
746  
747 0 ▶sub _load_audio_scan {
Subroutine _load_audio_scan: not called CC=22 SCAR=62.3
748 0 my ($self, $key, %opts) = @_;
749 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
750  
751 0 ▶ return if defined $self->{_loaded_audio_scan};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_audio_scan"} 0 0 0
752 0 $self->{_loaded_audio_scan} = 1;
753  
754 0 ▶ return unless defined $self->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"path"} 0 0 0
755  
756 # Check for module;
757 0 ▶ if (defined(my $data = eval {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $data = eval { do { local $ENV{"AUDIO_SCAN_NO_ARTWORK"} = 1; require Audio::Scan; "Audio::Scan"->import; "Audio::Scan"->scan($self->{"path"}) } })) 0 0 0
758 0 local $ENV{AUDIO_SCAN_NO_ARTWORK} = 1;
759 0 require Audio::Scan;
760 0 Audio::Scan->import();
761 0 Audio::Scan->scan($self->{path});
762 })) {
763 0 my $info = $data->{info};
764 0 my $tags = $data->{tags};
765  
766 0 foreach my $key (keys %{$info}) {
767 0 my $value = $info->{$key};
768 0 my $pv_key;
769  
770 0 ▶ next unless defined($value) && length($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
771 0 ▶ next if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 0 0
772  
773 0 $pv_key = $self->_dynamic_property(audio_scan_info => $key);
774 0 $pv->{$pv_key} = {raw => $value};
775 }
776  
777 0 foreach my $key (keys %{$tags}) {
778 0 my $value = $tags->{$key};
779 0 my $pv_key;
780  
781 0 ▶ next unless defined($value) && length($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
782 0 ▶ next if ref $value;
Branch: 1 branch
BranchTrueFalseTotal
if ref $value 0 0 0
783  
784 0 $pv_key = $self->_dynamic_property(audio_scan_tags => $key);
785 0 $pv->{$pv_key} = {raw => $value};
786 }
787  
788 {
789 0 my $style;
790  
791 0 ▶ if ($self->_check_mediatype(qw(application/ogg audio/ogg video/ogg audio/flac))) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->_check_mediatype('application/ogg', 'audio/ogg', 'video/ogg', 'audio/flac')) { } 0 0 0
elsif ($self->_check_mediatype('audio/x-wav')) { } 0 0 0
792 0 $style = 'vorbiscomments';
793 } elsif ($self->_check_mediatype(qw(audio/x-wav))) {
794 0 $style = 'riffwave';
795 } else {
796 0 $style = 'id3'; # bad guess
797 }
798  
799 0 ▶ if (defined($style) && defined(my $map = $_audio_scan_tags{$style})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $style and defined(my $map = $_audio_scan_tags{$style})) 0 0 0
Condition0%0/3
defined $style and defined(my $map = $_audio_scan_tags{$style})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $style and defined(my $map = $_audio_scan_tags{$style})
defined $style defined(my $map = $_audio_scan_tags{$style})
Truth table0%0/3
A and B
A= defined $styleB= defined(my $map = $_audio_scan_tags{$style})
ABresult
0X0
100
111
800 0 foreach my $key (keys %{$map}) {
801 0 my $src_pv_key = $self->_dynamic_property(audio_scan_tags => $map->{$key});
802 0 my $pv_key = $self->_dynamic_property(audio_scan => $key);
803 0 my $value = $pv->{$src_pv_key};
804  
805 0 ▶ if (defined($value) && ref($value) eq 'HASH' && defined($value->{raw})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and ref $value eq "HASH" and defined $value->{"raw"}) 0 0 0
Condition0%0/6
defined $value and ref $value eq "HASH" and defined $value->{"raw"}
!ll&&!rl&&r
000
defined $value and ref $value eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $value and ref $value eq "HASH" and defined $value->{"raw"}
defined $value ref $value eq "HASH" defined $value->{"raw"}
Truth table0%0/4
A and B and C
A= defined $valueB= ref $value eq "HASH"C= defined $value->{"raw"}
ABCresult
0XX0
10X0
1100
1111
806 0 $pv->{$pv_key} = {raw => $value->{raw}};
807 }
808 }
809 }
810 }
811 }
812 }
813  
814 0 ▶sub _load_barcodes {
Subroutine _load_barcodes: not called CC=7 SCAR=40.3
815 0 my ($self, $key, %opts) = @_;
816 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
817 0 my @barcodes;
818  
819 0 ▶ return if defined $self->{_loaded_barcodes};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_barcodes"} 0 0 0
820 0 $self->{_loaded_barcodes} = 1;
821  
822 0 ▶ return unless defined $self->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"path"} 0 0 0
823 0 ▶ return unless eval { require Data::URIID::Barcode; 1; };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require Data::URIID::Barcode; 1 } } 0 0 0
824  
825 0 @barcodes = eval { Data::URIID::Barcode->sheet(filename => $self->{path}) };
826  
827 0 ▶ if (scalar @barcodes) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @barcodes) 0 0 0
828 0 $pv->{data_uriid_barcodes} = [map {{raw => $_}} @barcodes];
829 }
830 }
831  
832 0 ▶sub _load_libpng {
Subroutine _load_libpng: not called CC=12 SCAR=50.5
833 0 my ($self, $key, %opts) = @_;
834 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
835  
836 0 ▶ return if defined $self->{_loaded_libpng};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_libpng"} 0 0 0
837 0 $self->{_loaded_libpng} = 1;
838  
839 0 ▶ return unless $self->_check_mediatype(qw(image/png));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_check_mediatype("image/png") 0 0 0
840 0 ▶ return unless defined $self->{path};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"path"} 0 0 0
841 0 ▶ return unless eval { require Image::PNG::Libpng; 1; };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require Image::PNG::Libpng; 1 } } 0 0 0
842  
843 0 ▶ if (defined(my $png = eval {Image::PNG::Libpng::read_png_file($self->{path})})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $png = eval { do { Image::PNG::Libpng::read_png_file($self->{"path"}) } })) 0 0 0
844 0 my $IHDR = $png->get_IHDR;
845  
846 0 $pv->{libpng_ihdr_width} = {raw => $IHDR->{width}};
847 0 $pv->{libpng_ihdr_height} = {raw => $IHDR->{height}};
848  
849 0 ▶ if (defined(my $ct = $_PNG_colour_types{$IHDR->{color_type}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $ct = $_PNG_colour_types{$IHDR->{"color_type"}})) 0 0 0
850 0 $pv->{libpng_ihdr_color_type} = {raw => $IHDR->{color_type}, ise => $ct->{ise}};
851 }
852  
853 0 ▶ if (defined(my $PLTE = eval {$png->get_PLTE})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $PLTE = eval { do { $png->get_PLTE } })) 0 0 0
854 0 ▶ if (eval { require Data::URIID::Colour; 1; }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require Data::URIID::Colour; 1 } }) 0 0 0
855 my @colours = map {{
856 0 raw => Data::URIID::Colour->new(rgb => sprintf('#%02x%02x%02x', $_->{red}, $_->{green}, $_->{blue})),
857 0 }} @{$PLTE};
858 0 ▶ $pv->{libpng_plte_colours} = \@colours if scalar @colours;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @colours 0 0 0
859 }
860 }
861 }
862 }
863  
864 0 ▶sub _load_riff__load_subchunks {
Subroutine _load_riff__load_subchunks: not called CC=16 SCAR=56.1
865 0 my ($self, $fh, $offset, $length, $chunk_common) = @_;
866 0 my $end = $offset + $length;
867 0 my @ret;
868  
869 0 require Data::Identifier::Generate;
870  
871 0 ▶ while ($offset < ($end - 8)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < $end - 8) 0 0 0
872 0 my $header;
873 my $chunk_length;
874 0 my $subtype;
875 0 my $skip = 8;
876 0 my $inner_type;
877  
878 0 $fh->seek($offset, SEEK_SET);
879  
880 0 ▶ croak 'IO error' if read($fh, $header, 8) != 8;
Branch: 1 branch
BranchTrueFalseTotal
if read($fh, $header, 8) != 8 0 0 0
881  
882 0 $chunk_length = unpack('V', substr($header, 4, 4, ''));
883 0 ▶ croak sprintf('Bad length: %u (max: %u - %u = %u)', $chunk_length, $length, $skip, $length - $skip) if $chunk_length > ($length - $skip);
Branch: 1 branch
BranchTrueFalseTotal
if $chunk_length > $length - $skip 0 0 0
884  
885 0 $skip += $chunk_length;
886 0 ▶ $skip += 1 if $chunk_length & 1; # Additional padding byte
Branch: 1 branch
BranchTrueFalseTotal
if $chunk_length & 1 0 0 0
887  
888 0 ▶ if ($header eq 'RIFF' || $header eq 'LIST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($header eq "RIFF" or $header eq "LIST") 0 0 0
Condition0%0/3
$header eq "RIFF" or $header eq "LIST"
l!l&&r!l&&!r
000
MC/DC0%0/2
$header eq "RIFF" or $header eq "LIST"
$header eq "RIFF" $header eq "LIST"
Truth table0%0/3
A or B
A= $header eq "RIFF"B= $header eq "LIST"
ABresult
1X1
011
000
889 0 ▶ croak 'IO error' if read($fh, $subtype, 4) != 4;
Branch: 1 branch
BranchTrueFalseTotal
if read($fh, $subtype, 4) != 4 0 0 0
890 }
891  
892 {
893 0 my $displayname;
894  
895 0 ▶ if (defined $subtype) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $subtype) { } 0 0 0
896 0 ▶ $displayname = sprintf('%s/%s', $header, $subtype) if $header =~ /^[0-9a-zA-Z_ ]{4}\z/ && $subtype =~ /^[0-9a-zA-Z_ ]{4}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $header =~ /^[0-9a-zA-Z_ ]{4}\z/u and $subtype =~ /^[0-9a-zA-Z_ ]{4}\z/u 0 0 0
Condition0%0/3
$header =~ /^[0-9a-zA-Z_ ]{4}\z/u and $subtype =~ /^[0-9a-zA-Z_ ]{4}\z/u
!ll&&!rl&&r
000
MC/DC0%0/2
$header =~ /^[0-9a-zA-Z_ ]{4}\z/u and $subtype =~ /^[0-9a-zA-Z_ ]{4}\z/u
$header =~ /^[0-9a-zA-Z_ ]{4}\z/u $subtype =~ /^[0-9a-zA-Z_ ]{4}\z/u
Truth table0%0/3
A and B
A= $header =~ /^[0-9a-zA-Z_ ]{4}\z/uB= $subtype =~ /^[0-9a-zA-Z_ ]{4}\z/u
ABresult
0X0
100
111
897 } else {
898 0 ▶ $displayname = $header if $header =~ /^[0-9a-zA-Z_ ]{4}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $header =~ /^[0-9a-zA-Z_ ]{4}\z/u 0 0 0
899 }
900  
901 0 ▶ $displayname =~ s/\s+\z// if defined $displayname;
Branch: 1 branch
BranchTrueFalseTotal
if defined $displayname 0 0 0
902  
903 0 ▶ $inner_type = Data::Identifier::Generate->generic(
Branch: 1 branch
BranchTrueFalseTotal
defined $subtype ? : 0 0 0
904 namespace => 'a416135e-c0b0-4d40-8eb0-24f164c0ad74',
905 input => $header.(defined $subtype ? $subtype : ''),
906 displayname => $displayname,
907 );
908  
909 0 $inner_type->register;
910 }
911  
912 push(@ret, File::Information::Chunk->_new(
913 0 ▶ %{$chunk_common},
Branch: 2 branches
BranchTrueFalseTotal
defined $subtype ? : 0 0 0
defined $subtype ? : 0 0 0
914 start => $offset,
915 size => $chunk_length + 8,
916 inner_start => $offset + 8,
917 inner_size => $chunk_length,
918 outer_type => {ise => $_wk{defined $subtype ? 'riff-master-chunk' : 'riff-slave-chunk'}->{ise}},
919 0 inner_type => {ise => $inner_type->uuid},
920 subchunks => (defined $subtype ? $self->_load_riff__load_subchunks($fh, $offset + 12, $chunk_length - 4, $chunk_common) : undef),
921 ));
922  
923 0 $offset += $skip,
924 $length -= $skip;
925 }
926  
927 0 return \@ret;
928 }
929  
930 0 ▶sub _load_riff {
Subroutine _load_riff: not called CC=8 SCAR=42.8
931 0 my ($self, $key, %opts) = @_;
932 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
933 0 my %chunk_common;
934  
935 0 ▶ return if defined $self->{_loaded_riff};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_riff"} 0 0 0
936 0 $self->{_loaded_riff} = 1;
937  
938 0 ▶ if (defined(my $inode = eval { $self->inode })) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $inode = eval { do { $self->inode } })) 0 0 0
939 0 ▶ if (defined(my $header = eval {$inode->peek(required => 4*3)})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $header = eval { do { $inode->peek("required", 12) } })) 0 0 0
940 0 my $size = $self->get('size');
941 0 my $fh;
942  
943 0 ▶ return unless substr($header, 0, 4) eq 'RIFF';
Branch: 1 branch
BranchTrueFalseTotal
unless substr($header, 0, 4) eq "RIFF" 0 0 0
944 0 ▶ return unless substr($header, 4, 4) eq pack('V', $size - 8);
Branch: 1 branch
BranchTrueFalseTotal
unless substr($header, 4, 4) eq pack("V", $size - 8) 0 0 0
945  
946 0 $fh = $inode->_get_fh;
947  
948 0 $pv->{riff_format} = {raw => substr($header, 8, 4)};
949  
950 0 require File::Information::Chunk;
951  
952 0 %chunk_common = (
953 instance => $self->instance,
954 parent => $self,
955 inode => $self->inode,
956 );
957 0 $pv->{riff_root_chunk} = {raw => $self->_load_riff__load_subchunks($fh, 0, $size, \%chunk_common)->[0]};
958 }
959 }
960 }
961  
962 0 ▶sub _load_riff_chunks {
Subroutine _load_riff_chunks: not called CC=9 SCAR=45.0
963 0 my ($self, $key, %opts) = @_;
964 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
965 0 my $chunk_inner_type;
966  
967 0 ▶ return if defined $self->{_loaded_riff_chunks};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_riff_chunks"} 0 0 0
968 0 $self->{_loaded_riff_chunks} = 1;
969  
970 0 $chunk_inner_type = $self->get('chunk_inner_type', as => 'ise', default => undef);
971 0 ▶ return unless defined $chunk_inner_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chunk_inner_type 0 0 0
972  
973 0 ▶ if ($chunk_inner_type eq 'e3596805-82a2-572a-88af-ab3ce127bb10') { # 'fmt '
Branch: 2 branches
BranchTrueFalseTotal
if ($chunk_inner_type eq 'e3596805-82a2-572a-88af-ab3ce127bb10') { } 0 0 0
elsif ($chunk_inner_type eq '41ee7c44-704c-50fc-99b7-a2fed7456b4c') { } 0 0 0
974 0 my ($AudioFormat, $NbrChannels, $Frequency, $BytePerSec, $BytePerBloc, $BitsPerSample) = unpack('vvVVvv', $self->peek(required => 16));
975 0 $pv->{riff_wave_fmt_format} = {raw => $AudioFormat, ise => sprintf('%08x-0000-0010-8000-00aa00389b71', $AudioFormat)};
976 0 $pv->{riff_wave_fmt_channels} = {raw => $NbrChannels};
977 0 $pv->{riff_wave_fmt_frequency} = {raw => $Frequency};
978 0 $pv->{riff_wave_fmt_bytes_per_second} = {raw => $BytePerSec};
979 0 $pv->{riff_wave_fmt_bytes_per_block} = {raw => $BytePerBloc};
980 0 $pv->{riff_wave_fmt_bits_per_sample} = {raw => $BitsPerSample};
981  
982 0 ▶ if ($NbrChannels == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($NbrChannels == 1) { } 0 0 0
elsif ($NbrChannels == 2) { } 0 0 0
983 0 $pv->{riff_wave_fmt_channels}{ise} = $_wk{'mono'}{ise};
984 } elsif ($NbrChannels == 2) {
985 0 $pv->{riff_wave_fmt_channels}{ise} = $_wk{'l-r-stereo'}{'ise'};
986 }
987 } elsif ($chunk_inner_type eq '41ee7c44-704c-50fc-99b7-a2fed7456b4c') { # 'fact'
988 0 my ($frames) = unpack('V', $self->peek(required => 4));
989 0 $pv->{riff_wave_fact_frames} = {raw => $frames};
990 }
991 }
992  
993 0 ▶sub _load_flac {
Subroutine _load_flac: not called CC=12 SCAR=50.5
994 0 my ($self, $key, %opts) = @_;
995 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
996 0 my $fh;
997 my $data;
998 0 my @blocks;
999 0 my %chunk_common;
1000  
1001 0 ▶ return if defined $self->{_loaded_flac};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_flac"} 0 0 0
1002 0 $self->{_loaded_flac} = 1;
1003  
1004 0 ▶ return unless $self->_check_mediatype(qw(audio/flac));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_check_mediatype("audio/flac") 0 0 0
1005  
1006 0 $fh = $self->inode->_get_fh;
1007 0 ▶ return if read($fh, $data, 4) != 4 || $data ne 'fLaC';
Branch: 1 branch
BranchTrueFalseTotal
if read($fh, $data, 4) != 4 or $data ne "fLaC" 0 0 0
Condition0%0/3
read($fh, $data, 4) != 4 or $data ne "fLaC"
l!l&&r!l&&!r
000
MC/DC0%0/2
read($fh, $data, 4) != 4 or $data ne "fLaC"
read($fh, $data, 4) != 4 $data ne "fLaC"
Truth table0%0/3
A or B
A= read($fh, $data, 4) != 4B= $data ne "fLaC"
ABresult
1X1
011
000
1008  
1009 0 require File::Information::Chunk;
1010  
1011 0 %chunk_common = (
1012 instance => $self->instance,
1013 parent => $self,
1014 inode => $self->inode,
1015 outer_type => {ise => '71edae67-d10e-48d3-ab69-4dfc88e9081c'}, # flac-metadata-block
1016 );
1017  
1018 0 ▶ while (read($fh, $data, 4) == 4) {
Branch: 1 branch
BranchTrueFalseTotal
if (read($fh, $data, 4) == 4) 0 0 0
1019 0 my $start = $fh->tell - 4;
1020 0 my ($first, $second, $tail) = unpack('CCn', $data);
1021 0 my $length = ($second << 8) + $tail;
1022  
1023 push(@blocks, File::Information::Chunk->_new(
1024 %chunk_common,
1025 start => $start,
1026 size => $length + 4,
1027 inner_start => $start + 4,
1028 inner_size => $length,
1029 inner_type => {ise => $_flac_metadata_blocks{$first & 0x7F}->{ise}},
1030 0 ));
1031  
1032 0 ▶ if (($first & 0x7F) == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (($first & 127) == 1) 0 0 0
1033 # This is a padding block. It is always boring.
1034 0 ▶ (($blocks[-1]->{properties_values} //= {})->{current} //= {})->{boring} = {raw => 1};
Condition0%0/4
+($blocks[-1]{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$blocks[-1]{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($blocks[-1]{"properties_values"} //= {})->{"current"} //= {}
+($blocks[-1]{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$blocks[-1]{"properties_values"} //= {}
$blocks[-1]{"properties_values"}
Truth table0%0/2
A
A= +($blocks[-1]{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $blocks[-1]{"properties_values"}
Aresult
11
00
1035 }
1036  
1037 0 ▶ last if $first & 0x80;
Branch: 1 branch
BranchTrueFalseTotal
if $first & 128 0 0 0
1038  
1039 0 $fh->seek($length, SEEK_CUR);
1040 }
1041  
1042 0 $pv->{flac_file_metadata} = [map {{raw => $_}} @blocks];
1043 }
1044  
1045 0 ▶sub _load_flac_metadata_blocks__read24 {
Subroutine _load_flac_metadata_blocks__read24: not called CC=1 SCAR=6.9
1046 0 my ($v) = @_;
1047 0 my ($x, $y) = unpack('Cn', ${$v});
1048 0 substr(${$v}, 0, 3, '');
1049 0 return ($x << 16) | $y;
1050 }
1051  
1052 0 ▶sub _load_flac_metadata_blocks__read_string {
Subroutine _load_flac_metadata_blocks__read_string: not called CC=1 SCAR=6.9
1053 0 state $UTF8 = do { require Encode; Encode::find_encoding('UTF-8') };
1054 0 my ($v) = @_;
1055 0 my $len = unpack('V', ${$v});
1056 0 my $s = $UTF8->decode(substr(${$v}, 4, $len));
1057 0 substr(${$v}, 0, $len + 4, '');
1058 0 return $s;
1059 }
1060  
1061 0 ▶sub _load_flac_metadata_blocks {
Subroutine _load_flac_metadata_blocks: not called CC=10 SCAR=47.0
1062 0 my ($self, $key, %opts) = @_;
1063 0 ▶ my $pv = ($self->{properties_values} //= {})->{current} //= {};
Condition0%0/4
+($self->{"properties_values"} //= {})->{"current"} //= {}
l!l
00
$self->{"properties_values"} //= {}
l!l
00
MC/DC0%0/1
+($self->{"properties_values"} //= {})->{"current"} //= {}
+($self->{"properties_values"} //= {})->{"current"}
MC/DC0%0/1
$self->{"properties_values"} //= {}
$self->{"properties_values"}
Truth table0%0/2
A
A= +($self->{"properties_values"} //= {})->{"current"}
Aresult
11
00
Truth table0%0/2
A
A= $self->{"properties_values"}
Aresult
11
00
1064 0 my $chunk_inner_type;
1065  
1066 0 ▶ return if defined $self->{_loaded_flac_metadata_blocks};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_loaded_flac_metadata_blocks"} 0 0 0
1067 0 $self->{_loaded_flac_metadata_blocks} = 1;
1068  
1069 0 $chunk_inner_type = $self->get('chunk_inner_type', as => 'ise', default => undef);
1070 0 ▶ return unless defined $chunk_inner_type;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chunk_inner_type 0 0 0
1071  
1072 0 ▶ if ($chunk_inner_type eq '92fd400d-4c47-5db2-b237-f3a0baf5343b') {
Branch: 2 branches
BranchTrueFalseTotal
if ($chunk_inner_type eq '92fd400d-4c47-5db2-b237-f3a0baf5343b') { } 0 0 0
elsif ($chunk_inner_type eq 'bdf21d34-8843-5f1e-8a5f-776c151991cd') { } 0 0 0
1073 0 my $data = $self->peek(required => 34);
1074 0 ▶ return if length($data) != 34;
Branch: 1 branch
BranchTrueFalseTotal
if length $data != 34 0 0 0
1075  
1076 0 $pv->{flac_streaminfo_min_block_size} = {raw => vec($data, 0, 16)};
1077 0 $pv->{flac_streaminfo_max_block_size} = {raw => vec($data, 1, 16)};
1078 0 substr($data, 0, 2*2, '');
1079  
1080 0 $pv->{flac_streaminfo_min_frame_size} = {raw => _load_flac_metadata_blocks__read24(\$data)};
1081 0 $pv->{flac_streaminfo_max_frame_size} = {raw => _load_flac_metadata_blocks__read24(\$data)};
1082  
1083 {
1084 0 my ($x, $y) = unpack('NN', $data);
1085 0 substr($data, 0, 8, '');
1086  
1087 0 $pv->{flac_streaminfo_sample_rate} = {raw => $x >> 12};
1088 0 $pv->{flac_streaminfo_channels} = {raw => (($x >> 9) & 0x07) + 1};
1089 0 $pv->{flac_streaminfo_bits} = {raw => (($x >> 4) & 0x1F) + 1};
1090  
1091 0 $pv->{flac_streaminfo_total_samples}= {raw => (($x & 0xF) << 32) | $y};
1092 }
1093  
1094 0 $pv->{flac_streaminfo_md5_checksum} = {raw => unpack('H32', $data)};
1095  
1096 # Data Description
1097 # u(16) The minimum block size (in samples) used in the stream, excluding the last block.
1098 # u(16) The maximum block size (in samples) used in the stream.
1099 # u(24) The minimum frame size (in bytes) used in the stream. A value of 0 signifies that the value is not known.
1100 # u(24) The maximum frame size (in bytes) used in the stream. A value of 0 signifies that the value is not known.
1101 # u(20) Sample rate in Hz.
1102 # u(3) (number of channels)-1. FLAC supports from 1 to 8 channels.
1103 # u(5) (bits per sample)-1. FLAC supports from 4 to 32 bits per sample.
1104 # u(36) Total number of interchannel samples in the stream. A value of 0 here means the number of total samples is unknown.
1105 # u(128) MD5 checksum of the unencoded audio data. This allows the decoder to determine if an error exists in the audio data even when, despite the error, the bitstream itself is valid. A value
1106 # of 0 signifies that the value is not known.
1107 } elsif ($chunk_inner_type eq 'bdf21d34-8843-5f1e-8a5f-776c151991cd') {
1108 0 my $data = $self->peek(required => 8, wanted => 1024);
1109 0 my $len;
1110  
1111 0 $pv->{flac_vorbiscomment_vendor} = {raw => _load_flac_metadata_blocks__read_string(\$data)};
1112  
1113 0 $len = unpack('V', $data);
1114 0 substr($data, 0, 4, '');
1115  
1116 0 ▶ for (my $i = 0; $i < $len; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
1117 0 my ($k, $v) = _load_flac_metadata_blocks__read_string(\$data) =~ /^([\x20-\x3E\x3F-\x7D]+)=(.*)\z/s;
1118 0 my $pv_key = $self->_dynamic_property(flac_vorbiscomment_comment => uc($k));
1119 0 ▶ my $e = $pv->{$pv_key} //= [];
Condition0%0/2
$pv->{$pv_key} //= []
l!l
00
MC/DC0%0/1
$pv->{$pv_key} //= []
$pv->{$pv_key}
Truth table0%0/2
A
A= $pv->{$pv_key}
Aresult
11
00
1120 0 push(@{$e}, {raw => $v});
1121 }
1122 }
1123 }
1124  
1125 3 1;
1126  
1127 __END__
« lib/File/Information.pm ↑ Summary lib/File/Information/Filesystem.pm »