Tag/Generic.pm

filter: Statementstmt 68.8% 106 / 154 Branchbran 26.0% 12 / 46 Conditioncond 36.8% 7 / 19 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 84.6% 22 / 26 Podpod 100% 18 / 18 totaltotal 60.5% 166 / 274 CC 32 SCAR 37.8
CC
32
Cov
57%
simple_compare
136.4
wav_out
42.0
simplify
5.1
CRAP 44.0
↑ Summary Tag/Test.pm »
1 package Music::Tag::Generic;
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 = '.4101';
4  
5 # Copyright © 2007,2008,2009,2010 Edward Allen III. Some rights reserved.
6  
7 #
8 # You may distribute under the terms of either the GNU General Public
9 # License or the Artistic License, as specified in the README file.
10 #
11  
12 6 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use vars qw($AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 6 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 6 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
18 6 my $class = shift;
19 6 my $parent = shift;
20 6 ▶ my $options = shift || {};
Condition50%1/2
shift() || {}
l!l
60
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
21 6 my $self = {};
22 6 bless $self, $class;
23 6 $self->info($parent);
24 6 $self->options($options);
25 6 return $self;
26 }
27  
28 77 ▶sub info {
Subroutine info: called CC=3 SCAR=11.0
Pod documented
29 77 my $self = shift;
30 77 my $val = shift;
31 77 ▶ if ( defined $val && ref $val ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and ref $val) 8 69 77
Condition66%2/3
defined $val and ref $val
!ll&&!rl&&r
6908
MC/DC50%1/2
defined $val and ref $val
defined $val ref $val
Truth table66%2/3
A and B
A= defined $valB= ref $val
ABresult
0X0
100
111
32 8 $self->{info} = $val;
33 8 weaken $self->{info};
34 }
35 77 return $self->{info};
36 }
37  
38 0 ▶sub required_values {
Subroutine required_values: not called CC=1 SCAR=0.0
Pod documented
39 }
40  
41 0 ▶sub set_values {
Subroutine set_values: not called CC=1 SCAR=0.0
Pod documented
42 }
43  
44 0 ▶sub saved_values {
Subroutine saved_values: not called CC=1 SCAR=0.0
Pod documented
45 }
46  
47 2 ▶sub get_tag {
Subroutine get_tag: called CC=1 SCAR=0.0
Pod documented
48 }
49  
50 2 ▶sub set_tag {
Subroutine set_tag: called CC=1 SCAR=0.0
Pod documented
51 }
52  
53 2 ▶sub strip_tag {
Subroutine strip_tag: called CC=1 SCAR=0.0
Pod documented
54 }
55  
56 2 ▶sub close {
Subroutine close: called CC=1 SCAR=0.0
Pod documented
57 }
58  
59 12 ▶sub tagchange {
Subroutine tagchange: called CC=3 SCAR=11.2
Pod documented
60 12 my $self = shift;
61 12 my $tag = lc(shift);
62 12 ▶ my $to = shift || $self->info->get_data($tag) || "";
Condition60%3/5
shift() || $self->info->get_data($tag) || ''
l!l
120
shift() or $self->info->get_data($tag)
l!l&&r!l&&!r
2100
MC/DC0%0/2
shift() || $self->info->get_data($tag) || ''
shift() $self->info->get_data($tag)
Truth table66%2/3
A or B
A= shift()B= $self->info->get_data($tag)
ABresult
1X1
011
000
63 12 $self->status( $self->info->_tenprint( $tag, 'bold blue', 15 ) . '"' . $to . '"' );
64 12 return $self->info->changed(1);
65 }
66  
67 12 ▶sub simplify {
Subroutine simplify: called CC=5 SCAR=16.2
Pod documented
68 12 my $self = shift;
69 12 my $text = shift;
70 12 chomp $text;
71 12 ▶ return $text unless $text;
Branch: 1 branch
BranchTrueFalseTotal
unless $text 0 12 12
72  
73 12 ▶ if ( $self->options->{Unaccent} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->{"Unaccent"}) 0 12 12
74 0 $text = Text::Unaccent::PurePerl::unac_string($text);
75 }
76  
77 12 $text = lc($text);
78  
79 12 $text =~ s/\[[^\]]+\]//g;
80 12 $text =~ s/[\s_]/ /g;
81  
82 12 ▶ if ( length($text) > 5 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $text > 5) 12 0 12
83 12 $text =~ s/\bthe\s//g;
84 12 $text =~ s/\ba\s//g;
85 12 $text =~ s/\ban\s//g;
86 12 $text =~ s/\band\s//g;
87 12 $text =~ s/\ble\s//g;
88 12 $text =~ s/\bles\s//g;
89 12 $text =~ s/\bla\s//g;
90 12 $text =~ s/\bde\s//g;
91 }
92 12 ▶ if ( $self->options->{Inflect} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->{'Inflect'}) { } 0 12 12
93 0 $text =~ s/(\.?\d+\,?\d*\.?\d*)/Lingua::EN::Inflect::NUMWORDS($1)/egxms;
94 }
95 else {
96 12 $text =~ s/\b10\s/ten /g;
97 12 $text =~ s/\b9\s/nine /g;
98 12 $text =~ s/\b8\s/eight /g;
99 12 $text =~ s/\b7\s/seven /g;
100 12 $text =~ s/\b6\s/six /g;
101 12 $text =~ s/\b5\s/five /g;
102 12 $text =~ s/\b4\s/four /g;
103 12 $text =~ s/\b3\s/three /g;
104 12 $text =~ s/\b2\s/two /g;
105 12 $text =~ s/\b1\s/one /g;
106 }
107  
108 12 $text =~ s/\sii\b/two/g;
109 12 $text =~ s/\siii\b/three/g;
110 12 $text =~ s/\siv\b/four/g;
111 12 $text =~ s/\sv\b/five/g;
112 12 $text =~ s/\svi\b/six/g;
113 12 $text =~ s/\svii\b/seven/g;
114 12 $text =~ s/\sviii\b/eight/g;
115  
116 # Don't translate IX because of a soft spot in my heart for the technologically rich planet.
117  
118 12 $text =~ s/[^a-z0-9]//g;
119 12 return $text;
120 }
121  
122 6 ▶sub simple_compare {
Subroutine simple_compare: called CC=16 SCAR=49.2
Pod documented
123 6 my $self = shift;
124 6 my $a = shift;
125 6 my $b = shift;
126 6 my $similar_percent = shift;
127 6 my $crop_percent = shift;
128  
129 6 my $sa = $self->simplify($a);
130 6 my $sb = $self->simplify($b);
131 6 ▶ if ( $sa eq $sb ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sa eq $sb) 4 2 6
132 4 return 1;
133 }
134  
135 2 ▶ return unless ( $similar_percent || $crop_percent );
Branch: 1 branch
BranchTrueFalseTotal
unless $similar_percent or $crop_percent 2 0 2
Condition33%1/3
$similar_percent or $crop_percent
l!l&&r!l&&!r
002
MC/DC0%0/2
$similar_percent or $crop_percent
$similar_percent $crop_percent
Truth table33%1/3
A or B
A= $similar_percentB= $crop_percent
ABresult
1X1
011
000
136  
137 0 my $la = length($sa);
138 0 my $lb = length($sb);
139 0 ▶ my $max = ( $la < $lb ) ? $lb : $la;
Branch: 1 branch
BranchTrueFalseTotal
$la < $lb ? : 0 0 0
140 0 ▶ my $min = ( $la < $lb ) ? $la : $lb;
Branch: 1 branch
BranchTrueFalseTotal
$la < $lb ? : 0 0 0
141  
142 0 ▶ return unless ( $min and $max );
Branch: 1 branch
BranchTrueFalseTotal
unless $min and $max 0 0 0
Condition0%0/3
$min and $max
!ll&&!rl&&r
000
MC/DC0%0/2
$min and $max
$min $max
Truth table0%0/3
A and B
A= $minB= $max
ABresult
0X0
100
111
143  
144 0 my $dist = undef;
145 0 ▶ if ( $self->options->{LevenshteinXS} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->options->{'LevenshteinXS'}) { } 0 0 0
elsif ($self->options->{'Levenshtein'}) { } 0 0 0
146 0 $dist = Text::LevenshteinXS::distance( $sa, $sb );
147 }
148 elsif ( $self->options->{Levenshtein} ) {
149 0 $dist = Text::Levenshtein::distance( $sa, $sb );
150 }
151 0 ▶ unless ($crop_percent) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($crop_percent) 0 0 0
152 0 $crop_percent = $similar_percent * ( 2 / 3 );
153 }
154  
155 0 ▶ if ( ( defined $dist ) && ( ( ( $min - $dist ) / $min ) >= $similar_percent ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dist and ($min - $dist) / $min >= $similar_percent) 0 0 0
Condition0%0/3
defined $dist and ($min - $dist) / $min >= $similar_percent
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dist and ($min - $dist) / $min >= $similar_percent
defined $dist ($min - $dist) / $min >= $similar_percent
Truth table0%0/3
A and B
A= defined $distB= ($min - $dist) / $min >= $similar_percent
ABresult
0X0
100
111
156 0 return -1;
157 }
158  
159 0 ▶ if ( $min < 10 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($min < 10) 0 0 0
160 0 return 0;
161 }
162 0 ▶ if ( ( ( ( 2 * $min ) - $max ) / $min ) <= $crop_percent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((2 * $min - $max) / $min <= $crop_percent) 0 0 0
163 0 return 0;
164 }
165 0 ▶ if ( substr( $sa, 0, $min ) eq substr( $sb, 0, $min ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($sa, 0, $min) eq substr($sb, 0, $min)) 0 0 0
166 0 return -1;
167 }
168 0 return 0;
169 }
170  
171 14 ▶sub status {
Subroutine status: called CC=1 SCAR=0.0
Pod documented
172 14 my $self = shift;
173 14 $self->info->status( ref($self), @_ );
174 14 return;
175 }
176  
177 1 ▶sub error {
Subroutine error: called CC=1 SCAR=0.0
Pod documented
178 1 my $self = shift;
179 1 carp( ref($self), " ", @_ );
180 1 return;
181 }
182  
183 2 ▶sub changed {
Subroutine changed: called CC=1 SCAR=0.0
Pod documented
184 2 my $self = shift;
185 2 return $self->info->changed(@_);
186 }
187  
188 0 ▶sub wav_out {
Subroutine wav_out: not called CC=6 SCAR=37.4
Pod documented
189 0 my $self = shift;
190 0 my $fh = shift;
191 0 ▶ if ( $self->options->{wav_out_system} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->options->{"wav_out_system"}) 0 0 0
192 0 my @sys = ();
193 0 foreach ( @{ $self->options->{wav_out_system} } ) {
194 0 my $a = $_;
195 0 $a =~ s/\[FILENAME\]/$self->info->get_data('filename')/ge;
196 0 push @sys, $a;
197 }
198 0 $self->status( 0, "Executing ", join( " ", @sys ) );
199 0 my $in;
200 0 ▶ if ( open( $in, '-|', @sys ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open $in, "-|", @sys) 0 0 0
201 0 binmode $in;
202 0 binmode $fh;
203 0 my $buffer = "";
204 0 ▶ while ( my $count = sysread( $in, $buffer, 1024 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $count = sysread($in, $buffer, 1024)) 0 0 0
205 0 my $wrote = 0;
206 0 ▶ while ( $wrote < $count ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($wrote < $count) 0 0 0
207 0 $wrote += syswrite( $fh, $buffer, ( $count - $wrote ), $wrote );
208 }
209 0 $buffer = "";
210 }
211 0 return 1;
212 }
213 0 CORE::close($in);
214 0 return 0;
215 }
216 0 return;
217 }
218  
219 89 ▶sub options {
Subroutine options: called CC=2 SCAR=6.9
Pod documented
220 89 my $self = shift;
221 89 ▶ unless ( exists $self->{_options} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"_options"}) 8 81 89
222 8 $self->{_options} = Config::Options->new( $self->default_options );
223 }
224 89 return $self->{_options}->options(@_);
225 }
226  
227 6 ▶sub default_options { return {} }
Subroutine default_options: called CC=1 SCAR=0.0
Pod documented
228  
229 8 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.0
230 8 my $self = shift;
231 8 ▶ if ( exists $self->{info} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"info"}) 8 0 8
232 8 delete $self->{info};
233 }
234 8 return;
235 }
236  
237 6 1;
238  
239 __END__
↑ Summary Tag/Test.pm »