Tag.pm

filter: Statementstmt 76.4% 478 / 625 Branchbran 54.6% 117 / 214 Conditioncond 49.4% 42 / 85 MC/DCmcdc 21.5% 11 / 51 Subroutinesub 78.3% 83 / 106 Podpod 100% 29 / 29 totaltotal 68.4% 760 / 1110 CC 149 SCAR 25.6
CC
149
Cov
69%
picture
110.0
picture_filename
72.0
_isutf8
42.0
CRAP 12.9
« Tag/Test.pm ↑ Summary Tag/Auto.pm »
1 package Music::Tag;
2 6 ▶use strict; use warnings; use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 our $VERSION = '0.4103';
4  
5 # Copyright © 2007,2008,2009,2010 Edward Allen III. Some rights reserved.
6 #
7 # You may distribute under the terms of either the GNU General Public
8 # License or the Artistic License, as specified in the README file.
9  
10  
11 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use Locale::Country;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use Config::Options;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use Digest::SHA1;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use IO::Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶use Music::Tag::Generic;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 6 ▶use DateTimeX::Easy;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 6 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 #use vars qw(%DataMethods);
29 6 my %DataMethods;
30 my $DefaultOptions;
31 6 my @PLUGINS;
32 6 my $PBP_METHODS = 1;
33 6 my $TRADITIONAL_METHODS = 1;
34 6 my %METHODS = ();
35 6 my ( $SHA1_SIZE, $SLURP_SIZE, $TENPRINT_SIZE );
36 6 Readonly::Scalar $SHA1_SIZE => 4 * 4096;
37 6 Readonly::Scalar $SLURP_SIZE => 1024;
38 6 Readonly::Scalar $TENPRINT_SIZE => 12;
39 7 ▶sub default_options {
Subroutine default_options: called CC=1 SCAR=0.0
Pod documented
40 7 my $self = shift;
41 7 return $DefaultOptions;
42 }
43  
44 2 ▶sub LoadOptions {
Subroutine LoadOptions: called CC=3 SCAR=11.0
Pod documented
45 2 my $self = shift;
46 2 my $optfile = shift;
47 2 ▶ if ( ref $self ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self) { } 1 1 2
elsif ($self) { } 1 0 1
48 1 return $self->options->fromfile_perl($optfile);
49 }
50 elsif ($self) {
51 1 return $DefaultOptions->fromfile_perl($optfile);
52 }
53 }
54  
55 6 ▶sub new {
Subroutine new: called CC=5 SCAR=16.6
Pod documented
56 6 my $class = shift;
57 6 my $filename = shift;
58 6 ▶ my $options = shift || {};
Condition100%2/2
shift() || {}
l!l
42
MC/DC100%1/1
shift() || {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
59 6 ▶ my $plugin = shift || 'Auto';
Condition100%2/2
shift() || 'Auto'
l!l
51
MC/DC100%1/1
shift() || 'Auto'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
60 6 ▶ my $data = shift || {};
Condition50%1/2
shift() || {}
l!l
06
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
61  
62 6 my $self = {};
63 6 $self->{data} = $data;
64 6 ▶ if ( ref $class ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $class) { } 0 6 6
65 0 my $clone = { %{$class} };
66 0 bless $clone, ref $class;
67 0 return $clone;
68 }
69 else {
70 6 bless $self, $class;
71 6 $self->{_plugins} = [];
72 6 $self->options($options);
73 6 $self->filename($filename);
74 6 $self->{changed} = 0;
75 }
76  
77 6 $self->_test_modules();
78  
79 6 $self->add_plugin( $plugin, $options );
80 6 return $self;
81  
82 }
83  
84 6 ▶sub _test_modules {
Subroutine _test_modules: called CC=4 SCAR=14.2
85 6 my $self = shift;
86 6 my %module_map = (
87 'ANSIColor' => 'Term::ANSIColor',
88 'LevenshteinXS' => 'Text::LevenshteinXS',
89 'Levenshtein' => 'Text::Levenshtein',
90 'Unaccent' => 'Text::Unaccent::PurePerl',
91 'Inflect' => 'Lingua::EN::Inflect',
92 );
93 6 ▶ while ( my ( $k, $v ) = each %module_map ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %module_map) 30 6 36
94 30 ▶ if ( ( $self->options->{$k} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->{$k} and $self->_has_module($v)) { } 0 30 30
Condition66%2/3
$self->options->{$k} and $self->_has_module($v)
!ll&&!rl&&r
12180
MC/DC0%0/2
$self->options->{$k} and $self->_has_module($v)
$self->options->{$k} $self->_has_module($v)
Truth table66%2/3
A and B
A= $self->options->{$k}B= $self->_has_module($v)
ABresult
0X0
100
111
95 && ( $self->_has_module($v) ) ) {
96 0 $self->options->{$k} = 1;
97 }
98 else {
99 30 $self->options->{$k} = 0;
100 }
101 }
102 6 return;
103 }
104  
105 26 ▶sub _has_module {
Subroutine _has_module: called CC=2 SCAR=6.9
106 26 my $self = shift;
107 26 my $module = shift;
108 26 my $modfile = $module . '.pm';
109 26 $modfile =~ s/\:\:/\//g;
110 26 ▶ if ( eval { require $modfile; 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { require $modfile; 1 } }) { } 8 18 26
111 8 return 1;
112 }
113 else {
114 18 $self->status( 1, "Not loading $module: " . $@ );
115 18 return 0;
116 }
117 }
118  
119 7 ▶sub add_plugin {
Subroutine add_plugin: called CC=12 SCAR=29.3
Pod documented
120 7 my $self = shift;
121 7 my $object = shift;
122 7 ▶ my $opts = shift || {};
Condition50%1/2
shift() || {}
l!l
70
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
123 7 my $options = $self->options->clone;
124 7 $options->merge($opts);
125 7 ▶ my $type = shift || 0;
Condition100%2/2
shift() || 0
l!l
16
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
126 7 my $ref;
127 7 ▶ if ( ref $object ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $object) { } 0 7 7
128 0 $ref = $object;
129 0 $ref->info($self);
130 0 $ref->options($options);
131 }
132 else {
133 7 my ( $plugin, $popts ) = split( /:/, $object );
134 7 ▶ if ( $self->available_plugins($plugin) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->available_plugins($plugin)) { } 7 0 7
135 7 ▶ if ($popts) {
Branch: 1 branch
BranchTrueFalseTotal
if ($popts) 0 7 7
136 0 my @opts = split( /[;]/, $popts );
137 0 foreach (@opts) {
138 0 my ( $k, $v ) = split( /=/, $_ );
139 0 $options->options( $k, $v );
140 }
141 }
142 7 ▶ if (!eval {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { unless ($plugin =~ /::/) { $plugin = 'Music::Tag::' . $plugin; } ; if ($self->_has_module($plugin)) { $ref = $plugin->new($self, $options); } ; return 1 } }) 0 7 7
143 7 ▶ if ( not $plugin =~ /::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($plugin =~ /::/) 7 0 7
144 7 $plugin = 'Music::Tag::' . $plugin;
145 }
146 7 ▶ if ( $self->_has_module($plugin) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_has_module($plugin)) 7 0 7
147 7 $ref = $plugin->new( $self, $options );
148 }
149 7 return 1;
150 }
151 ) {
152 0 ▶ croak "Error loading plugin ${plugin}: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
153 }
154 }
155 else {
156 0 croak "Error loading plugin ${plugin}: Not Found";
157 }
158 }
159 7 ▶ if ($ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref) 6 1 7
160 6 push @{ $self->{_plugins} }, $ref;
161 }
162 7 return $ref;
163 }
164  
165 25 ▶sub plugin {
Subroutine plugin: called CC=4 SCAR=14.5
Pod documented
166 25 my $self = shift;
167 25 my $plugin = shift;
168 25 ▶ if ( defined $plugin ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $plugin) 25 0 25
169 25 foreach ( @{ $self->{_plugins} } ) {
170 25 ▶ if ( ref($_) =~ /$plugin$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref($_) =~ /$plugin$/) 25 0 25
171 25 return $_;
172 }
173 }
174 }
175 0 return;
176 }
177  
178 3 ▶sub get_tag {
Subroutine get_tag: called CC=1 SCAR=0.0
Pod documented
179 3 my $self = shift;
180 3 ▶ $self->_foreach_plugin( sub { $_[0]->get_tag } );
Subroutine __ANON__: called CC=1 SCAR=0.0
181 3 return $self;
182 }
183  
184 9 ▶sub _foreach_plugin {
Subroutine _foreach_plugin: called CC=4 SCAR=15.0
185 9 my $self = shift;
186 9 my $callback = shift;
187 9 foreach my $plugin ( @{ $self->{_plugins} } ) {
188 10 ▶ if ( ref $plugin ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $plugin) { } 10 0 10
elsif ($plugin) { } 0 0 0
189 10 &{$callback}($plugin);
190 }
191 elsif ($plugin) {
192 0 $self->error("Invalid Plugin in list: '$plugin'");
193 }
194 }
195 9 return $self;
196 }
197  
198 0 ▶sub set_tag {
Subroutine set_tag: not called CC=1 SCAR=6.9
Pod documented
199 0 my $self = shift;
200 0 ▶ $self->_foreach_plugin( sub { $_[0]->set_tag } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
201 0 return $self;
202 }
203  
204 0 ▶sub strip_tag {
Subroutine strip_tag: not called CC=1 SCAR=6.9
Pod documented
205 0 my $self = shift;
206 0 ▶ $self->_foreach_plugin( sub { $_[0]->strip_tag } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
207 0 return $self;
208 }
209  
210  
211 # In retrospect, this was misnamed. Too late now!
212 0 ▶sub close { ## no critic (ProhibitBuiltinHomonyms, ProhibitAmbiguousNames)
Subroutine close: not called CC=1 SCAR=6.9
Pod documented
213 0 my $self = shift;
214 return $self->_foreach_plugin(
215 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
216 0 $_[0]->close();
217  
218 #$_->{info} = undef;
219 #$_ = undef;
220 }
221 0 );
222 }
223  
224 15 ▶sub changed {
Subroutine changed: called CC=2 SCAR=6.9
Pod documented
225 15 my $self = shift;
226 15 my $new = shift;
227 15 ▶ if ( defined $new ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 14 1 15
228 14 $self->{changed}++;
229 }
230 15 return $self->{changed};
231 }
232  
233 1 ▶sub data {
Subroutine data: called CC=2 SCAR=7.4
Pod documented
234 1 my $self = shift;
235 1 my $new = shift;
236 1 ▶ if ( defined $new ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $new) 0 1 1
237 0 $self->{data} = $new;
238 }
239 1 return $self->{data};
240 }
241  
242 258 ▶sub options { ## no critic (Subroutines::RequireArgUnpacking)
Subroutine options: called CC=2 SCAR=6.9
Pod documented
243 258 my $self = shift;
244 258 ▶ if ( not exists $self->{_options} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_options"}) 6 252 258
245 6 $self->{_options} = Config::Options->new( $self->default_options );
246 }
247 258 return $self->{_options}->options(@_);
248 }
249  
250 2 ▶sub setfileinfo {
Subroutine setfileinfo: called CC=2 SCAR=6.9
Pod documented
251 2 my $self = shift;
252 2 ▶ if ( $self->filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->filename) 1 1 2
253 1 my $st = stat $self->filename;
254 1 $self->mepoch( $st->mtime );
255 1 $self->bytes( $st->size );
256 1 return $st;
257 }
258 1 return;
259 }
260  
261 1 ▶sub sha1 {
Subroutine sha1: called CC=5 SCAR=28.3
Pod documented
262 1 my $self = shift;
263 1 ▶ if ( not( ( $self->filename ) && ( -e $self->filename ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->filename and -e $self->filename) 1 0 1
Condition33%1/3
$self->filename and -e $self->filename
!ll&&!rl&&r
100
MC/DC0%0/2
$self->filename and -e $self->filename
$self->filename -e $self->filename
Truth table33%1/3
A and B
A= $self->filenameB= -e $self->filename
ABresult
0X0
100
111
264 1 return undef; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
265 }
266 0 my $maxsize = $SHA1_SIZE;
267 0 my $in = IO::File->new();
268 0 ▶ $in->open( $self->filename, '<' ) or die "Bad file: $self->filename\n";
Branch: 1 branch
BranchTrueFalseTotal
$in->open($self->filename, "<") or die "Bad file: $self->filename\n" 0 0 0
269 0 my $st = stat $self->filename;
270 0 my $sha1 = Digest::SHA1->new();
271 0 $sha1->add( pack( 'V', $st->size ) );
272 0 my $d;
273  
274 0 ▶ if ( $in->read( $d, $maxsize ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in->read($d, $maxsize)) 0 0 0
275 0 $sha1->add($d);
276 }
277 0 $in->close();
278 0 return $sha1->hexdigest;
279 }
280  
281 0 ▶sub picture {
Subroutine picture: not called CC=10 SCAR=47.0
Pod documented
282 0 my $self = shift;
283 0 ▶ unless ( exists $self->{data}->{PICTURE} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"data"}{"PICTURE"}) 0 0 0
284 0 $self->{data}->{PICTURE} = {};
285 }
286 0 ▶ $self->{data}->{PICTURE} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 0 0
287  
288 0 ▶ if ( ( exists $self->{data}->{PICTURE}->{filename} )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'data'}{'PICTURE'}{'filename'} and $self->{'data'}{'PICTURE'}{'filename'}) { } 0 0 0
elsif (exists $self->{'data'}{'PICTURE'}{'_Data'} and length $self->{'data'}{'PICTURE'}{'_Data'}) { } 0 0 0
Condition0%0/3
exists $self->{"data"}{"PICTURE"}{"filename"} and $self->{"data"}{"PICTURE"}{"filename"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"data"}{"PICTURE"}{"filename"} and $self->{"data"}{"PICTURE"}{"filename"}
exists $self->{"data"}{"PICTURE"}{"filename"} $self->{"data"}{"PICTURE"}{"filename"}
Truth table0%0/3
A and B
A= exists $self->{"data"}{"PICTURE"}{"filename"}B= $self->{"data"}{"PICTURE"}{"filename"}
ABresult
0X0
100
111
289 && ( $self->{data}->{PICTURE}->{filename} ) ) {
290 0 my $root = File::Spec->rootdir();
291 0 ▶ if ( $self->filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->filename) 0 0 0
292 0 $root = $self->filedir;
293 }
294 my $picfile =
295 File::Spec->rel2abs( $self->{data}->{PICTURE}->{filename},
296 0 $root );
297 0 ▶ if ( -f $picfile ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $picfile) 0 0 0
298 0 ▶ if ( $self->{data}->{PICTURE}->{_Data} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"}{"PICTURE"}{"_Data"}) 0 0 0
299 0 delete $self->{data}->{PICTURE}->{_Data};
300 }
301 0 my %ret = %{ $self->{data}->{PICTURE} }; # Copy ref
302 0 $ret{_Data} = read_file( $picfile, 'binmode' => ':raw' );
303 0 return \%ret;
304 }
305 }
306 ▶ elsif (( exists $self->{data}->{PICTURE}->{_Data} )
Condition0%0/3
exists $self->{"data"}{"PICTURE"}{"_Data"} and length $self->{"data"}{"PICTURE"}{"_Data"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"data"}{"PICTURE"}{"_Data"} and length $self->{"data"}{"PICTURE"}{"_Data"}
exists $self->{"data"}{"PICTURE"}{"_Data"} length $self->{"data"}{"PICTURE"}{"_Data"}
Truth table0%0/3
A and B
A= exists $self->{"data"}{"PICTURE"}{"_Data"}B= length $self->{"data"}{"PICTURE"}{"_Data"}
ABresult
0X0
100
111
307 && ( length $self->{data}->{PICTURE}->{_Data} ) ) {
308 0 return $self->{data}->{PICTURE};
309 }
310 0 return {};
311 }
312  
313 0 ▶sub get_picture {
Subroutine get_picture: not called CC=1 SCAR=6.9
Pod documented
314 0 my $self = shift;
315 0 return $self->picture;
316 }
317  
318 0 ▶sub set_picture {
Subroutine set_picture: not called CC=1 SCAR=6.9
Pod documented
319 0 my $self = shift;
320 0 my $value = shift;
321 0 return $self->picture($value);
322 }
323  
324 0 ▶sub picture_filename {
Subroutine picture_filename: not called CC=8 SCAR=42.8
Pod documented
325 0 my $self = shift;
326 0 my $new = shift;
327 0 ▶ if ($new) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new) 0 0 0
328 0 ▶ if ( not exists $self->{data}->{PICTURE} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"data"}{"PICTURE"}) 0 0 0
329 0 $self->{data}->{PICTURE} = {};
330 }
331 0 $self->{data}->{PICTURE}->{filename} = $new;
332 }
333 0 ▶ if ( ( exists $self->{data}->{PICTURE} )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'data'}{'PICTURE'} and $self->{'data'}{'PICTURE'}{'filename'}) { } 0 0 0
elsif (exists $self->{'data'}{'PICTURE'} and $self->{'data'}{'PICTURE'}{'_Data'} and length $self->{'data'}{'PICTURE'}{'_Data'}) { } 0 0 0
Condition0%0/3
exists $self->{"data"}{"PICTURE"} and $self->{"data"}{"PICTURE"}{"filename"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{"data"}{"PICTURE"} and $self->{"data"}{"PICTURE"}{"filename"}
exists $self->{"data"}{"PICTURE"} $self->{"data"}{"PICTURE"}{"filename"}
Truth table0%0/3
A and B
A= exists $self->{"data"}{"PICTURE"}B= $self->{"data"}{"PICTURE"}{"filename"}
ABresult
0X0
100
111
334 && ( $self->{data}->{PICTURE}->{filename} ) ) {
335 0 return $self->{data}->{PICTURE}->{filename};
336 }
337 ▶ elsif (( exists $self->{data}->{PICTURE} )
Condition0%0/6
exists $self->{"data"}{"PICTURE"} and $self->{"data"}{"PICTURE"}{"_Data"} and length $self->{"data"}{"PICTURE"}{"_Data"}
!ll&&!rl&&r
000
exists $self->{"data"}{"PICTURE"} and $self->{"data"}{"PICTURE"}{"_Data"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $self->{"data"}{"PICTURE"} and $self->{"data"}{"PICTURE"}{"_Data"} and length $self->{"data"}{"PICTURE"}{"_Data"}
exists $self->{"data"}{"PICTURE"} $self->{"data"}{"PICTURE"}{"_Data"} length $self->{"data"}{"PICTURE"}{"_Data"}
Truth table0%0/4
A and B and C
A= exists $self->{"data"}{"PICTURE"}B= $self->{"data"}{"PICTURE"}{"_Data"}C= length $self->{"data"}{"PICTURE"}{"_Data"}
ABCresult
0XX0
10X0
1100
1111
338 && ( $self->{data}->{PICTURE}->{_Data} )
339 && ( length( $self->{data}->{PICTURE}->{_Data} ) ) ) {
340 0 return 0;
341 }
342  
343 # Value is undefined, so return undef.
344 0 return undef; ## no critic (Subroutines::ProhibitExplicitReturnUndef)
345 }
346  
347 0 ▶sub picture_exists { goto &has_picture; }
Subroutine picture_exists: not called CC=1 SCAR=6.9
Pod documented
348 1 ▶sub has_picture {
Subroutine has_picture: called CC=7 SCAR=32.3
Pod documented
349 1 my $self = shift;
350 1 ▶ if ( ( exists $self->{data}->{PICTURE}->{filename} )
Branch: 2 branches
BranchTrueFalseTotal
if (exists $self->{'data'}{'PICTURE'}{'filename'} and $self->{'data'}{'PICTURE'}{'filename'}) { } 0 1 1
elsif (exists $self->{'data'}{'PICTURE'}{'_Data'} and length $self->{'data'}{'PICTURE'}{'_Data'}) { } 0 2 2
Condition33%1/3
exists $self->{"data"}{"PICTURE"}{"filename"} and $self->{"data"}{"PICTURE"}{"filename"}
!ll&&!rl&&r
100
MC/DC0%0/2
exists $self->{"data"}{"PICTURE"}{"filename"} and $self->{"data"}{"PICTURE"}{"filename"}
exists $self->{"data"}{"PICTURE"}{"filename"} $self->{"data"}{"PICTURE"}{"filename"}
Truth table33%1/3
A and B
A= exists $self->{"data"}{"PICTURE"}{"filename"}B= $self->{"data"}{"PICTURE"}{"filename"}
ABresult
0X0
100
111
351 && ( $self->{data}->{PICTURE}->{filename} ) ) {
352 0 my $root = File::Spec->rootdir();
353 0 ▶ if ( $self->filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->filename) 0 0 0
354 0 $root = $self->filedir;
355 }
356 my $picfile =
357 File::Spec->rel2abs( $self->{data}->{PICTURE}->{filename},
358 0 $root );
359 0 ▶ if ( -f $picfile ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $picfile) { } 0 0 0
360 0 return 1;
361 }
362 else {
363 0 $self->status( 0, 'Picture: ', $picfile, ' does not exists' );
364 }
365 }
366 ▶ elsif (( exists $self->{data}->{PICTURE}->{_Data} )
Condition33%1/3
exists $self->{"data"}{"PICTURE"}{"_Data"} and length $self->{"data"}{"PICTURE"}{"_Data"}
!ll&&!rl&&r
100
MC/DC0%0/2
exists $self->{"data"}{"PICTURE"}{"_Data"} and length $self->{"data"}{"PICTURE"}{"_Data"}
exists $self->{"data"}{"PICTURE"}{"_Data"} length $self->{"data"}{"PICTURE"}{"_Data"}
Truth table33%1/3
A and B
A= exists $self->{"data"}{"PICTURE"}{"_Data"}B= length $self->{"data"}{"PICTURE"}{"_Data"}
ABresult
0X0
100
111
367 && ( length $self->{data}->{PICTURE}->{_Data} ) ) {
368 0 return 1;
369 }
370 1 return 0;
371 }
372  
373 11 ▶sub available_plugins {
Subroutine available_plugins: called CC=4 SCAR=13.9
Pod documented
374 11 my $self = shift;
375 11 my $check = shift;
376 11 ▶ if ($check) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check) 10 1 11
377 10 foreach (@PLUGINS) {
378 24 ▶ if ( $check eq $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($check eq $_) 9 15 24
379 9 return 1;
380 }
381 }
382 1 return 0;
383 }
384 1 return @PLUGINS;
385 }
386  
387  
388 6 ▶sub datamethods {
Subroutine datamethods: called CC=4 SCAR=13.9
Pod documented
389 6 my $package = shift;
390 6 ▶ if (ref $package) { $package = ref $package; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $package) 6 0 6
391 6 my $add = shift;
392 6 ▶ if ($add) {
Branch: 1 branch
BranchTrueFalseTotal
if ($add) 1 5 6
393 1 my $new = lc($add);
394 1 $DataMethods{$new} = 1;
395 1 ▶ if ( !defined &{ 'get_' . $new } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &{'get_' . $new;}) 1 0 1
396 1 $package->_make_accessor( $new => {} );
397 }
398 }
399 6 return [ keys %DataMethods ];
400 }
401  
402 1 ▶sub used_datamethods {
Subroutine used_datamethods: called CC=3 SCAR=11.0
Pod documented
403 1 my $self = shift;
404 1 my @ret = ();
405 1 foreach my $m ( @{ $self->datamethods } ) {
406 92 ▶ if ($self->has_data($m)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_data($m)) 2 90 92
407 2 push @ret, $m;
408 }
409 }
410 1 return \@ret;
411 }
412  
413 0 ▶sub wav_out {
Subroutine wav_out: not called CC=1 SCAR=6.9
Pod documented
414 0 my $self = shift;
415 0 my $fh = shift;
416 0 my $out;
417 $self->_foreach_plugin(
418 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
419 0 $out = $_->wav_out($fh);
420 0 ▶ return $out if ( defined $out );
Branch: 1 branch
BranchTrueFalseTotal
if defined $out 0 0 0
421 }
422 0 );
423 0 return $out;
424 }
425  
426 # This method is far from perfect. It can't be perfect.
427 # It won't mangle valid UTF-8, however.
428 # Just be sure to always return perl utf8 in plugins when possible.
429  
430 0 ▶sub _isutf8 {
Subroutine _isutf8: not called CC=6 SCAR=37.4
431 0 my $self = shift;
432 0 my $in = shift;
433  
434 # If it is a proper utf8, with tag, just return it.
435 0 ▶ if ( Encode::is_utf8( $in, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&Encode::is_utf8($in, 1)) 0 0 0
436 0 return $in;
437 }
438  
439 0 my $has7f = 0;
440 0 foreach ( split( //, $in ) ) {
441 0 ▶ if ( ord($_) >= 0x7f ) { ## no critic (ProhibitMagicNumbers)
Branch: 1 branch
BranchTrueFalseTotal
if (ord $_ >= 127) 0 0 0
442 0 $has7f++;
443 }
444 }
445  
446 # No char >7F it is prob. valid ASCII, just return it.
447 0 ▶ if ( !$has7f ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($has7f) 0 0 0
448 0 utf8::upgrade($in);
449 0 return $in;
450 }
451  
452 # See if it is a valid UTF-16 encoding.
453 #my $out;
454 #eval {
455 # $out = decode('UTF-16', $in, 1);
456 #};
457 #return $out unless $@;
458  
459 # See if it is a valid UTF-16LE encoding.
460 #my $out;
461 #eval {
462 # $out = decode('UTF-16LE', $in, 1);
463 #};
464 #return $out unless $@;
465  
466 # See if it is a valid UTF-8 encoding.
467 0 my $out;
468 0 ▶ if ( eval { $out = decode( 'UTF-8', $in, 1 ); return 1 } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { $out = &decode("UTF-8", $in, 1); return 1 } }) 0 0 0
469 0 utf8::upgrade($out);
470 0 return $out;
471 }
472  
473 # Finally just give up and return it.
474  
475 0 utf8::upgrade($in);
476 0 return $in;
477 }
478  
479 491 ▶sub _add_to_namespace {
Subroutine _add_to_namespace: called CC=12 SCAR=25.7
480 491 my ( $package, $attrname, $reader, $writer, $predicate ) = @_;
481 491 $METHODS{$attrname} = {reader => $reader};
482 491 ▶ if ($predicate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($predicate) 491 0 491
483 491 $METHODS{$attrname}->{predicate} = $predicate;
484 }
485 {
486 ## no critic (ProhibitProlongedStrictureOverride,ProhibitNoStrict)
487 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
488  
489 491 ▶ if ($TRADITIONAL_METHODS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TRADITIONAL_METHODS) 491 0 491
490 491 my $readwriter;
491 491 ▶ if ($writer) {
Branch: 2 branches
BranchTrueFalseTotal
if ($writer) { } 486 5 491
elsif ($reader) { } 5 0 5
492 486 $readwriter = _generate_readwriter( $package, $reader, $writer );
493 486 $METHODS{$attrname}->{writer} = $writer;
494 } elsif ($reader) {
495 5 $readwriter = $reader;
496 }
497 491 $METHODS{$attrname}->{readwriter} = $readwriter;
498 491 ▶ if ($readwriter) { *{ $package . '::' . $attrname } = $readwriter; }
Branch: 1 branch
BranchTrueFalseTotal
if ($readwriter) 491 0 491
499 }
500 491 ▶ if ($PBP_METHODS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($PBP_METHODS) 491 0 491
501 491 ▶ if ($writer) { *{ $package . '::set_' . $attrname } = $writer; }
Branch: 1 branch
BranchTrueFalseTotal
if ($writer) 486 5 491
502 491 ▶ if ($reader) { *{ $package . '::get_' . $attrname } = $reader; }
Branch: 1 branch
BranchTrueFalseTotal
if ($reader) 491 0 491
503 }
504 491 ▶ if ($TRADITIONAL_METHODS || $PBP_METHODS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TRADITIONAL_METHODS or $PBP_METHODS) 491 0 491
Condition33%1/3
$TRADITIONAL_METHODS or $PBP_METHODS
l!l&&r!l&&!r
49100
MC/DC0%0/2
$TRADITIONAL_METHODS or $PBP_METHODS
$TRADITIONAL_METHODS $PBP_METHODS
Truth table33%1/3
A or B
A= $TRADITIONAL_METHODSB= $PBP_METHODS
ABresult
1X1
011
000
505 491 ▶ if ($predicate) { *{ $package . '::has_' . $attrname } = $predicate; }
Branch: 1 branch
BranchTrueFalseTotal
if ($predicate) 491 0 491
506 }
507 ## use critic
508 }
509 }
510  
511 118 ▶sub _get_method {
Subroutine _get_method: called CC=3 SCAR=12.3
512 118 my $self = shift;
513 118 my $method = shift;
514 118 my $attr = shift;
515 118 ▶ if ((exists $METHODS{$attr}) && (ref $METHODS{$attr})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $METHODS{$attr} and ref $METHODS{$attr}) { } 118 0 118
Condition33%1/3
exists $METHODS{$attr} and ref $METHODS{$attr}
!ll&&!rl&&r
00118
MC/DC0%0/2
exists $METHODS{$attr} and ref $METHODS{$attr}
exists $METHODS{$attr} ref $METHODS{$attr}
Truth table33%1/3
A and B
A= exists $METHODS{$attr}B= ref $METHODS{$attr}
ABresult
0X0
100
111
516 118 return $METHODS{$attr}->{$method};
517 }
518 else {
519 0 ▶ return sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
520 }
521 }
522  
523 2 ▶sub _get_reader {
Subroutine _get_reader: called CC=1 SCAR=0.0
524 2 my $self = shift;
525 2 my $attr = shift;
526 2 $self->_get_method('reader',$attr);
527 }
528  
529 2 ▶sub _get_writer {
Subroutine _get_writer: called CC=1 SCAR=0.0
530 2 my $self = shift;
531 2 my $attr = shift;
532 2 $self->_get_method('writer',$attr);
533 }
534  
535 0 ▶sub _get_predicate {
Subroutine _get_predicate: not called CC=1 SCAR=6.9
536 0 my $self = shift;
537 0 my $attr = shift;
538 0 $self->_get_method('predicate',$attr);
539 }
540  
541 114 ▶sub _do_method {
Subroutine _do_method: called CC=1 SCAR=0.0
542 114 my $self = shift;
543 114 my $method = shift;
544 114 my $attr = shift;
545 114 my @p = @_;
546 114 &{$self->_get_method($method,$attr)}($self,@p);
547 }
548  
549 13 ▶sub get_data {
Subroutine get_data: called CC=1 SCAR=0.0
Pod documented
550 13 my $self = shift;
551 13 my @opts = @_;
552 13 $self->_do_method('reader',@opts);
553 }
554  
555 9 ▶sub set_data {
Subroutine set_data: called CC=1 SCAR=0.0
Pod documented
556 9 my $self = shift;
557 9 my @opts = @_;
558 9 $self->_do_method('writer',@opts);
559 }
560  
561 92 ▶sub has_data {
Subroutine has_data: called CC=1 SCAR=0.0
Pod documented
562 92 my $self = shift;
563 92 my @opts = @_;
564 92 $self->_do_method('predicate',@opts);
565 }
566  
567 481 ▶sub _generate_reader {
Subroutine _generate_reader: called CC=5 SCAR=16.3
568 481 my ( $package, $attr, $options ) = @_;
569 481 ▶ my $default = $options->{default} || undef;
Condition50%1/2
$options->{'default'} || undef
l!l
0481
MC/DC0%0/1
$options->{'default'} || undef
$options->{'default'}
Truth table50%1/2
A
A= $options->{'default'}
Aresult
11
00
570 481 ▶ my $trigger = $options->{readtrigger} || undef;
Condition50%1/2
$options->{'readtrigger'} || undef
l!l
0481
MC/DC0%0/1
$options->{'readtrigger'} || undef
$options->{'readtrigger'}
Truth table50%1/2
A
A= $options->{'readtrigger'}
Aresult
11
00
571 481 ▶ my $outfilter = $options->{outfilter} || undef;
Condition100%2/2
$options->{'outfilter'} || undef
l!l
110371
MC/DC100%1/1
$options->{'outfilter'} || undef
$options->{'outfilter'}
Truth table100%2/2
A
A= $options->{'outfilter'}
Aresult
11
00
572 481 ▶ my $builder = $options->{builder} || undef;
Condition100%2/2
$options->{'builder'} || undef
l!l
15466
MC/DC100%1/1
$options->{'builder'} || undef
$options->{'builder'}
Truth table100%2/2
A
A= $options->{'builder'}
Aresult
11
00
573 123 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=18.3
574 123 my $self = shift;
575 123 ▶ if ( ( not exists $self->{data}->{$attr} )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"data"}{$attr} and defined $self->{"data"}{$attr}) 7 116 123
Condition66%2/3
exists $self->{"data"}{$attr} and defined $self->{"data"}{$attr}
!ll&&!rl&&r
70116
MC/DC50%1/2
exists $self->{"data"}{$attr} and defined $self->{"data"}{$attr}
exists $self->{"data"}{$attr} defined $self->{"data"}{$attr}
Truth table66%2/3
A and B
A= exists $self->{"data"}{$attr}B= defined $self->{"data"}{$attr}
ABresult
0X0
100
111
576 or ( not defined $self->{data}->{$attr} ) ) {
577 7 ▶ if ($builder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($builder) { } 2 5 7
578 2 $self->{data}->{$attr} = &{$builder}($self);
579 }
580 else {
581 5 return $default;
582 }
583 }
584 0 ▶ if ($trigger) { &{$trigger}( $self, $self->{data}->{$attr} ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($trigger) 0 118 118
585 return $outfilter
586 24 ? &{$outfilter}( $self, $self->{data}->{$attr} )
587 118 ▶ : $self->{data}->{$attr};
Branch: 1 branch
BranchTrueFalseTotal
$outfilter ? : 24 94 118
588 }
589 481 }
590  
591 386 ▶sub _generate_writer {
Subroutine _generate_writer: called CC=4 SCAR=14.5
592 386 my ( $package, $attr, $options ) = @_;
593 386 ▶ my $trigger = $options->{trigger} || undef;
Condition100%2/2
$options->{'trigger'} || undef
l!l
5381
MC/DC100%1/1
$options->{'trigger'} || undef
$options->{'trigger'}
Truth table100%2/2
A
A= $options->{'trigger'}
Aresult
11
00
594 386 ▶ my $filter = $options->{filter} || undef;
Condition100%2/2
$options->{'filter'} || undef
l!l
65321
MC/DC100%1/1
$options->{'filter'} || undef
$options->{'filter'}
Truth table100%2/2
A
A= $options->{'filter'}
Aresult
11
00
595 386 ▶ my $validator = $options->{validator} || undef;
Condition100%2/2
$options->{'validator'} || undef
l!l
10376
MC/DC100%1/1
$options->{'validator'} || undef
$options->{'validator'}
Truth table100%2/2
A
A= $options->{'validator'}
Aresult
11
00
596  
597 100 ▶ return sub {
Subroutine __ANON__: called CC=8 SCAR=23.6
598 100 my ( $self, $value ) = @_;
599 100 ▶ my $setvalue = $filter ? &{$filter}( $self, $value ) : $value;
Branch: 1 branch
BranchTrueFalseTotal
$filter ? : 19 81 100
600 100 ▶ if ( ($validator) && ( !&{$validator}( $self, $value ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($validator and not &{$validator;}($self, $value)) 0 100 100
Condition66%2/3
$validator and not &{$validator;}($self, $value)
!ll&&!rl&&r
9910
MC/DC0%0/2
$validator and not &{$validator;}($self, $value)
$validator not &{$validator;}($self, $value)
Truth table66%2/3
A and not(B)
A= $validatorB= not &{$validator;}($self, $value)
ABresult
0X0
100
111
601 0 ▶ $self->status(
Branch: 1 branch
BranchTrueFalseTotal
defined $setvalue ? : 0 0 0
602 0,
603 "Invalid value for $attr: ",
604 ( defined $setvalue ) ? $setvalue : 'UNDEFINED'
605 );
606 0 return;
607 }
608 100 ▶ if ( $self->options('verbose') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options("verbose")) 0 100 100
609 0 ▶ $self->status(
Branch: 1 branch
BranchTrueFalseTotal
defined $setvalue ? : 0 0 0
610 1,
611 "Setting $attr to ",
612 ( defined $setvalue ) ? $setvalue : 'UNDEFINED'
613 );
614 }
615 100 $self->{data}->{$attr} = $setvalue;
616 100 ▶ if ($trigger) { &{$trigger}( $self, $setvalue ); }
Branch: 1 branch
BranchTrueFalseTotal
if ($trigger) 2 98 100
617 100 return $self->{data}->{$attr};
618 }
619 386 }
620  
621 486 ▶sub _generate_readwriter {
Subroutine _generate_readwriter: called CC=1 SCAR=0.0
622 486 my ( $package, $reader, $writer ) = @_;
623 197 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
624 197 my ( $self, $value ) = @_;
625 197 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 88 109 197
626 88 return &{$writer}( $self, $value );
627 }
628 else {
629 109 return &{$reader}($self);
630 }
631 486 };
632 }
633  
634 391 ▶sub _generate_predicate {
Subroutine _generate_predicate: called CC=1 SCAR=0.0
635 391 my ( $package, $attr, $options ) = @_;
636 93 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
637 93 my $self = shift;
638 return ( ( exists $self->{data}->{$attr} )
639 93 ▶ && ( defined $self->{data}->{$attr} ) );
Condition66%2/3
exists $self->{'data'}{$attr} && defined $self->{'data'}{$attr}
!ll&&!rl&&r
9102
MC/DC50%1/2
exists $self->{'data'}{$attr} && defined $self->{'data'}{$attr}
exists $self->{'data'}{$attr} defined $self->{'data'}{$attr}
Truth table66%2/3
A && B
A= exists $self->{'data'}{$attr}B= defined $self->{'data'}{$attr}
ABresult
0X0
100
111
640 391 };
641 }
642  
643 361 ▶sub _make_accessor {
Subroutine _make_accessor: called CC=4 SCAR=13.9
644 361 my ( $package, $attrname, $options ) = @_;
645 361 ▶ my $attr = $options->{attr} || uc($attrname);
Condition66%2/3
$options->{'attr'} || uc $attrname
l!l&&r!l&&!r
203410
MC/DC0%0/2
$options->{'attr'} || uc $attrname
$options->{'attr'} uc $attrname
Truth table66%2/3
A || B
A= $options->{'attr'}B= uc $attrname
ABresult
1X1
011
000
646 361 my $reader = _generate_reader( $package, $attr, $options );
647 361 my $writer;
648 361 ▶ if ( !( ( exists $options->{readonly} ) && ( $options->{readonly} ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $options->{"readonly"} and $options->{"readonly"}) 356 5 361
Condition66%2/3
exists $options->{"readonly"} and $options->{"readonly"}
!ll&&!rl&&r
35605
MC/DC50%1/2
exists $options->{"readonly"} and $options->{"readonly"}
exists $options->{"readonly"} $options->{"readonly"}
Truth table66%2/3
A and B
A= exists $options->{"readonly"}B= $options->{"readonly"}
ABresult
0X0
100
111
649 356 $writer = _generate_writer( $package, $attr, $options );
650 }
651 361 my $predicate = _generate_predicate( $package, $attr, $options );
652 361 _add_to_namespace( $package, $attrname, $reader, $writer, $predicate );
653 361 return;
654 }
655  
656 30 ▶sub _make_datetime_accessor {
Subroutine _make_datetime_accessor: called CC=6 SCAR=18.0
657 30 my ( $package, $attrname, $options ) = @_;
658 30 ▶ my $attr = $options->{attr} || uc($attrname);
Condition33%1/3
$options->{'attr'} || uc $attrname
l!l&&r!l&&!r
0300
MC/DC0%0/2
$options->{'attr'} || uc $attrname
$options->{'attr'} uc $attrname
Truth table33%1/3
A || B
A= $options->{'attr'}B= uc $attrname
ABresult
1X1
011
000
659 10 ▶ my $filter = sub {
Subroutine __ANON__: called CC=3 SCAR=11.6
660 10 my ( $self, $value ) = @_;
661 10 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 10 0 10
662 10 ▶ if ( $value =~ /^\-?\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^\-?\d+$/) { } 7 3 10
663 7 return DateTime->from_epoch( epoch => $value );
664 }
665 else {
666 3 return DateTimeX::Easy->new($value);
667 }
668 0 $self->status( 0, "Invalid date set for ${attr}: ${value}" );
669 }
670 0 return;
671 30 };
672 30 $options->{filter} = $filter;
673  
674 30 my $predicate = _generate_predicate( $package, $attr, $options );
675 30 my $writer = _generate_writer( $package, $attr, $options );
676 30 my $dt_reader = _generate_reader( $package, $attr, $options );
677 _add_to_namespace( $package,
678 30 ▶ ( $options->{dtname} ? $options->{dtname} : $attrname . 'dt' ),
Branch: 1 branch
BranchTrueFalseTotal
$options->{'dtname'} ? : 10 20 30
679 $dt_reader, $writer, $predicate );
680  
681 30 ▶ $options->{outfilter} = sub { my ( $self, $val ) = @_; return $val->ymd };
Subroutine __ANON__: called CC=1 SCAR=0.0
682 30 my $date_reader = _generate_reader( $package, $attr, $options );
683 _add_to_namespace(
684 $package,
685 30 ▶ ( $options->{datename} ? $options->{datename} : $attrname . 'date' ),
Branch: 1 branch
BranchTrueFalseTotal
$options->{'datename'} ? : 10 20 30
686 $date_reader,
687 $writer,
688 $predicate
689 );
690  
691 $options->{outfilter} =
692 30 ▶ sub { my ( $self, $val ) = @_; return $val->ymd . ' ' . $val->hms };
Subroutine __ANON__: called CC=1 SCAR=0.0
693 30 my $time_reader = _generate_reader( $package, $attr, $options );
694 _add_to_namespace(
695 $package,
696 30 ▶ ( $options->{timename} ? $options->{timename} : $attrname . 'time' ),
Branch: 1 branch
BranchTrueFalseTotal
$options->{'timename'} ? : 10 20 30
697 $time_reader,
698 $writer,
699 $predicate
700 );
701  
702 $options->{outfilter} =
703 30 ▶ sub { my ( $self, $val ) = @_; return $val->epoch };
Subroutine __ANON__: called CC=1 SCAR=0.0
704 30 my $epoch_reader = _generate_reader( $package, $attr, $options );
705 _add_to_namespace(
706 $package,
707 ( $options->{epochname}
708 ? $options->{epochname}
709 30 ▶ : $attrname . 'epoch'
Branch: 1 branch
BranchTrueFalseTotal
$options->{'epochname'} ? : 10 20 30
710 ),
711 $epoch_reader,
712 $writer,
713 $predicate
714 );
715 30 return;
716 }
717  
718 10 ▶sub _make_ordinal_accessor {
Subroutine _make_ordinal_accessor: called CC=3 SCAR=11.4
719 10 my ( $package, $attrname, $options ) = @_;
720 10 my $attr = uc($attrname);
721 10 my $pos = $options->{pos_attr};
722 0 ▶ if ( !$pos ) { croak("pos_attr required\n"); return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($pos) 0 10 10
723 10 my $total = $options->{total_attr};
724 0 ▶ if ( !$total ) { croak("total_attr required\n"); return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($total) 0 10 10
725 1 ▶ my $writer = sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
726 1 my ( $self, $new ) = @_;
727 1 my ( $t, $tt ) = split( m{/}, $new );
728 1 ▶ if ($t) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t) 1 0 1
729 1 &{$self->_get_writer($pos)}($self,$t);
730 }
731 1 ▶ if ($tt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tt) 1 0 1
732 1 &{$self->_get_writer($total)}($self,$tt);
733 }
734 1 return $new;
735 10 };
736 1 ▶ my $reader = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
737 1 my $self = shift;
738 1 my $m = '_get_' . $pos;
739 1 my $t = &{$self->_get_reader($pos)}($self);
740 1 my $tt = &{$self->_get_reader($total)}($self);
741 1 my $r = '';
742 1 ▶ if ($t) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t) 1 0 1
743 1 $r .= $t;
744 }
745 1 ▶ if ($tt) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tt) 1 0 1
746 1 $r .= '/' . $tt;
747 }
748 1 return $r;
749 10 };
750 2 ▶ my $predicate = sub {
Subroutine __ANON__: called CC=3 SCAR=12.7
751 2 my $self = shift;
752 2 my ( $pp, $pt ) = ( 'has_' . $pos, 'has_' . $total );
753 2 ▶ if ( $self->$pp || $self->$pt ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->$pp or $self->$pt) 0 2 2
Condition33%1/3
$self->$pp or $self->$pt
l!l&&r!l&&!r
002
MC/DC0%0/2
$self->$pp or $self->$pt
$self->$pp $self->$pt
Truth table33%1/3
A or B
A= $self->$ppB= $self->$pt
ABresult
1X1
011
000
754 0 return 1;
755 }
756 2 return;
757 10 };
758 10 _add_to_namespace( $package, $attrname, $reader, $writer, $predicate );
759 10 return;
760 }
761  
762 15 ▶sub _make_list_accessor {
Subroutine _make_list_accessor: called CC=1 SCAR=0.0
763 15 my ( $package, $attrname, $options ) = @_;
764 4 ▶ $options->{filter} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
765 4 my ( $self, $value ) = @_;
766 4 my @ret = ();
767 4 ▶ if ( ref $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value) { } 2 2 4
768 2 push @ret, @{$value};
769 }
770 else {
771 2 push @ret, split( /\s*,\s*/, $value );
772 }
773 4 return \@ret;
774 15 };
775 15 _make_accessor( $package, $attrname, $options );
776 }
777  
778 32 ▶sub status { ## no critic (Subroutines::RequireArgUnpacking)
Subroutine status: called CC=6 SCAR=17.9
Pod documented
779 32 my $self = shift;
780 32 ▶ if ( not $self->options('quiet') ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->options("quiet")) 13 19 32
781 13 my $name = ref($self);
782 13 ▶ if ( $_[0] =~ /\:\:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /\:\:/) 4 9 13
783 4 $name = shift;
784 }
785 13 my $level = 0;
786 13 ▶ if ( $_[0] =~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^\d+$/) 9 4 13
787 9 $level = shift;
788 }
789 13 ▶ my $verbose = $self->options('verbose') || 0;
Condition50%1/2
$self->options('verbose') || 0
l!l
013
MC/DC0%0/1
$self->options('verbose') || 0
$self->options('verbose')
Truth table50%1/2
A
A= $self->options('verbose')
Aresult
11
00
790 13 ▶ if ( $level <= $verbose ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($level <= $verbose) 4 9 13
791 4 $name =~ s/^Music::Tag:://g;
792 4 print $self->_tenprint( $name, 'bold white', $TENPRINT_SIZE ), @_,
793 "\n";
794 }
795 }
796 32 return;
797 }
798  
799 16 ▶sub _tenprint {
Subroutine _tenprint: called CC=3 SCAR=11.8
800 16 my $self = shift;
801 16 my $text = shift;
802 16 ▶ my $_color = shift || 'bold yellow';
Condition50%1/2
shift() || 'bold yellow'
l!l
160
MC/DC0%0/1
shift() || 'bold yellow'
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
803 16 ▶ my $size = shift || $TENPRINT_SIZE;
Condition33%1/3
shift() || $TENPRINT_SIZE
l!l&&r!l&&!r
1600
MC/DC0%0/2
shift() || $TENPRINT_SIZE
shift() $TENPRINT_SIZE
Truth table33%1/3
A || B
A= shift()B= $TENPRINT_SIZE
ABresult
1X1
011
000
804 return
805 16 $self->_color($_color)
806 . sprintf( '%' . $size . 's: ', substr( $text, 0, $size ) )
807 . $self->_color('reset');
808 }
809  
810 32 ▶sub _color { ## no critic (Subroutines::RequireArgUnpacking)
Subroutine _color: called CC=2 SCAR=7.6
811 32 my $self = shift;
812 32 ▶ if ( $self->options->{ANSIColor} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->{'ANSIColor'}) { } 0 32 32
813 0 return Term::ANSIColor::color(@_);
814 }
815 else {
816 32 return '';
817 }
818 }
819  
820 0 ▶sub error { ## no critic (Subroutines::RequireArgUnpacking)
Subroutine error: not called CC=1 SCAR=6.9
Pod documented
821 0 my $self = shift;
822  
823 # unless ( $self->options('quiet') ) {
824 0 carp( ref($self), ' ', @_ );
825  
826 # }
827 0 return;
828 }
829  
830 5 ▶sub _create_attributes {
Subroutine _create_attributes: called CC=6 SCAR=19.4
831 5 my $package = shift;
832 5 my $params = shift;
833  
834 5 ▶ if ($params->{pbp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"pbp"}) 0 5 5
835 0 $PBP_METHODS = 1;
836 0 $TRADITIONAL_METHODS = 0;
837 }
838 5 ▶ if ($params->{traditional}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"traditional"}) 0 5 5
839 0 $TRADITIONAL_METHODS = 1;
840 }
841
842 0 ▶ if (ref $package) { $package = ref $package; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $package) 0 5 5
843 5 my @datamethods = qw(
844 album album_type albumartist albumartist_sortname albumid appleid
845 artist artist_end artist_start artist_start_time artist_start_epoch
846 artist_end_time artist_end_epoch artist_type artistid asin bitrate
847 booklet bytes codec comment compilation composer copyright country
848 countrycode disc discnum disctitle duration encoded_by encoder filename
849 frames framesize frequency gaplessdata genre ipod ipod_dbid
850 ipod_location ipod_trackid label lastplayedtime lastplayeddate
851 lastplayedepoch lyrics mb_albumid mb_artistid mb_trackid mip_puid
852 mtime mdate mepoch originalartist performer path picture playcount
853 postgap pregap rating albumrating recorddate recordtime releasedate
854 releasetime recordepoch releaseepoch samplecount secs songid sortname
855 stereo tempo title totaldiscs totaltracks track tracknum url user vbr
856 year upc ean jan filetype mip_fingerprint artisttags albumtags
857 tracktags);
858  
859 5 %DataMethods = map { $_ => { readwrite => 1 } } @datamethods;
860  
861 ## no critic (ProtectPrivateSubs)
862  
863 $package->_make_accessor(
864 'albumartist' => {
865 2 ▶ builder => sub { my $self = shift; return $self->artist() }
Subroutine __ANON__: called CC=1 SCAR=0.0
866 }
867 5 );
868 $package->_make_accessor(
869 'albumartist_sortname' => {
870 0 ▶ builder => sub { my $self = shift; return $self->sortname() }
Subroutine __ANON__: not called CC=1 SCAR=6.9
871 }
872 5 );
873 5 $package->_make_list_accessor( 'albumtags' => {} );
874 5 $package->_make_list_accessor( 'artisttags' => {} );
875 $package->_make_accessor(
876 'country' => {
877 attr => 'COUNTRYCODE',
878 0 ▶ filter => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
879 0 my ( $self, $new ) = @_;
880 0 return country2code($new);
881 },
882 1 ▶ outfilter => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
883 1 my ( $self, $value ) = @_;
884 1 return code2country($value);
885 }
886 }
887 5 );
888 5 $package->_make_ordinal_accessor(
889 'discnum',
890 { pos_attr => 'disc',
891 total_attr => 'totaldiscs',
892 }
893 );
894 $package->_make_accessor(
895 'secs',
896 { attr => 'DURATION',
897 1 ▶ filter => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
898 1 my ( $self, $new ) = @_;
899 1 return $new * 1000;
900 },
901 1 ▶ outfilter => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
902 1 my ( $self, $value ) = @_;
903 1 return int( $value / 1000 );
904 }
905 }
906 5 );
907 $package->_make_accessor(
908 'ean',
909 1 ▶ { validator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
910 1 my ( $self, $value ) = @_;
911 1 return $value =~ /^\d{13}$/;
912 },
913 5 alias => [qw(jan)],
914 }
915 );
916 $package->_make_accessor(
917 'filename',
918 4 ▶ { filter => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
919 4 my ( $self, $new ) = @_;
920 4 return File::Spec->rel2abs($new);
921 }
922 }
923 5 );
924 $package->_make_accessor(
925 'filedir',
926 { attr => 'FILENAME',
927 0 ▶ outfilter => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
928 0 my ( $self, $value ) = @_;
929 0 my ( $vol, $path, $file ) = File::Spec->splitpath($value);
930 0 return File::Spec->catpath( $vol, $path, '' );
931 },
932 5 readonly => 1,
933 }
934 );
935 5 $package->_make_accessor( 'artist', { alias => [qw(performer)] } );
936  
937 5 $package->_make_list_accessor( 'tracktags' => {} );
938  
939 5 $package->_make_ordinal_accessor(
940 'tracknum',
941 { pos_attr => 'track',
942 total_attr => 'totaltracks',
943 }
944 );
945  
946 $package->_make_accessor(
947 'upc',
948 { attr => 'EAN',
949 0 ▶ validator => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
950 0 my ( $self, $value ) = @_;
951 0 return $value =~ /^\d{13}$/;
952 },
953 0 ▶ filter => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
954 0 my ( $self, $value ) = @_;
955 0 return ( '0' . $value );
956 },
957 1 ▶ outfilter => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
958 1 my ( $self, $value ) = @_;
959 1 $value =~ s/^0//;
960 1 return $value;
961 }
962 }
963 5 );
964  
965 $package->_make_datetime_accessor(
966 'record' => {
967 2 ▶ trigger => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
968 2 my ( $self, $value ) = @_;
969 2 ▶ if ( $value->isa('DateTime') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value->isa("DateTime")) 2 0 2
970 2 $self->set_year( $value->year );
971 }
972 }
973 }
974 5 );
975 5 $package->_make_datetime_accessor( 'release' => {} );
976 5 $package->_make_datetime_accessor( 'm' => {} );
977 5 $package->_make_datetime_accessor('lastplayed');
978 5 $package->_make_datetime_accessor(
979 'artist_start' => {
980 timename => 'artist_start_time',
981 datename => 'artist_start',
982 epochname => 'artist_start_epoch',
983 dtname => 'artist_start_dt',
984 }
985 );
986 5 $package->_make_datetime_accessor(
987 'artist_end' => {
988 timename => 'artist_end_time',
989 datename => 'artist_end',
990 epochname => 'artist_end_epoch',
991 dtname => 'artist_end_dt',
992 }
993 );
994  
995 $package->_make_accessor(
996 'year' => {
997 0 ▶ builder => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
998 0 my $self = shift;
999 0 ▶ if ( $self->has_releasedt ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_releasedt) 0 0 0
1000 0 return $self->releasedt->year;
1001 }
1002 }
1003 }
1004 5 );
1005  
1006 5 $METHODS{'picture'} = {
1007 reader => \&get_picture,
1008 writer => \&set_picture,
1009 predicate => \&has_picture,
1010 };
1011  
1012  
1013 5 foreach my $m (@datamethods) {
1014 460 ▶ if ( ! exists $METHODS{$m}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $METHODS{$m}) 295 165 460
1015 295 $package->_make_accessor( $m => {} );
1016 }
1017 }
1018 ## use critic
1019 }
1020  
1021 5 ▶sub _find_plugins {
Subroutine _find_plugins: called CC=8 SCAR=20.9
1022 5 my $package = shift;
1023 0 ▶ if (ref $package) { $package = ref $package; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $package) 0 5 5
1024 5 my $me = $package;
1025 5 $me =~ s{::}{/}g;
1026 5 @PLUGINS = ();
1027 5 foreach my $d (@INC) {
1028 40 chomp $d;
1029 40 ▶ if ( -d "$d/$me/" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "$d/$me/") 15 25 40
1030 15 my $fdir = IO::Dir->new("$d/$me");
1031 15 ▶ if ( defined $fdir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fdir) 15 0 15
1032 15 ▶ while ( my $m = $fdir->read() ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $m = $fdir->read) 90 15 105
1033 90 ▶ next if $m eq 'Test.pm';
Branch: 1 branch
BranchTrueFalseTotal
if $m eq "Test.pm" 15 75 90
1034 75 ▶ if ( $m =~ /^(.*)\.pm$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m =~ /^(.*)\.pm$/) 45 30 75
1035 45 my $mod = $1;
1036 45 push @PLUGINS, $mod;
1037 }
1038 }
1039 }
1040 15 $fdir->close();
1041 }
1042 }
1043  
1044 }
1045  
1046 5 ▶sub import {
Subroutine import: called CC=3 SCAR=11.4
1047 5 my $package = shift;
1048 5 my $params = {};
1049 0 ▶ if ( ref $_[0] ) { $params = $_[0]; }
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0]) { } 0 5 5
elsif (not scalar @_ % 2) { } 5 0 5
1050 5 elsif ( !scalar @_ % 2 ) { $params = {@_}; }
1051 5 $package->_create_attributes($params);
1052 5 $package->_find_plugins($params);
1053 5 return 1;
1054 }
1055  
1056 6 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
1057 $DefaultOptions = Config::Options->new(
1058 { verbose => 0,
1059 quiet => 0,
1060 ANSIColor => 0,
1061 LevenshteinXS => 1,
1062 Levenshtein => 1,
1063 Unaccent => 1,
1064 Inflect => 0,
1065 optionfile =>
1066 6 [ '/etc/musictag.conf', $ENV{HOME} . '/.musictag.conf' ],
1067 }
1068 );
1069 }
1070  
1071 6 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
1072 6 my $self = shift;
1073 6 ▶ $self->_foreach_plugin( sub { $_[0]->{info} = undef } );
Subroutine __ANON__: called CC=1 SCAR=0.0
1074 6 return;
1075 }
1076  
1077 6 1;
1078 __END__
« Tag/Test.pm ↑ Summary Tag/Auto.pm »