lib/Astroboy/AlbumDir.pm

filter: Statementstmt 28.9% 31 / 107 Branchbran 0.0% 0 / 58 Conditioncond 0.0% 0 / 56 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 40.9% 9 / 22 Podpod 50.0% 6 / 12 totaltotal 16.3% 46 / 281 CC 46 SCAR 38.2
CC
46
Cov
14%
_ls_mp3s_aggree_on
131.1
new
90.0
refile
30.0
CRAP 45.6
« lib/Astroboy/AlbumFile.pm ↑ Summary lib/Astroboy.pm »
1 package Astroboy::AlbumDir;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 $VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)/g;
6 6 ▶use LEOCHARRE::Dir ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 6 ▶use Cwd;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Astroboy::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use LEOCHARRE::Class2;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 #use Smart::Comments '###';
11 6 ▶use Astroboy::AlbumFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 __PACKAGE__->make_accessor_setget(qw(abs_path errstr));
13 6 __PACKAGE__->make_accessor_setget_aref(qw(ls_trash ls_mp3 ls));
14  
15  
16  
17 0 ▶sub new {
Subroutine new: not called CC=9 SCAR=45.0
Pod documented
18 0 my $class = shift;
19 0 my $_abs = shift;
20 0 ▶ $_abs or croak('Missing abs path to dir argument');
Branch: 1 branch
BranchTrueFalseTotal
$_abs or croak("Missing abs path to dir argument") 0 0 0
21
22 0 ▶ my $abs_path = Cwd::abs_path($_abs) or carp("Can't abs_path() to $_abs") and return;
Branch: 1 branch
BranchTrueFalseTotal
my $abs_path = Cwd::abs_path($_abs) or carp("Can't abs_path() to $_abs") and return 0 0 0
Condition0%0/5
(my $abs_path = Cwd::abs_path($_abs)) || carp("Can't abs_path() to $_abs") && (return)
l!l&&r!l&&!r
000
carp("Can't abs_path() to $_abs") and return
!ll
00
MC/DC0%0/2
(my $abs_path = Cwd::abs_path($_abs)) || carp("Can't abs_path() to $_abs") && (return)
(my $abs_path = Cwd::abs_path($_abs)) carp("Can't abs_path() to $_abs")
Truth table0%0/3
A || B
A= (my $abs_path = Cwd::abs_path($_abs))B= carp("Can't abs_path() to $_abs")
ABresult
1X1
011
000
23  
24 0 ▶ -d $abs_path or carp("Not dir on disk: $abs_path") and return;
Branch: 1 branch
BranchTrueFalseTotal
-d $abs_path or carp("Not dir on disk: $abs_path") and return 0 0 0
Condition0%0/5
-d $abs_path || carp("Not dir on disk: $abs_path") && (return)
l!l&&r!l&&!r
000
carp("Not dir on disk: $abs_path") and return
!ll
00
MC/DC0%0/2
-d $abs_path || carp("Not dir on disk: $abs_path") && (return)
-d $abs_path carp("Not dir on disk: $abs_path")
Truth table0%0/3
A || B
A= -d $abs_pathB= carp("Not dir on disk: $abs_path")
ABresult
1X1
011
000
25  
26 0 my @ls = lsf($abs_path);
27  
28 0 my @mp3s = grep { /\.mp3$/i } @ls;
29 0 my @trash = grep { !/\.mp3$/i } @ls;
30
31 0 ▶ $ENV{HOME} or die("need env home to be set");
Branch: 1 branch
BranchTrueFalseTotal
$ENV{"HOME"} or die "need env home to be set" 0 0 0
32
33 0 my $self = {
34 abs_path => $abs_path,
35 ls => \@ls,
36 ls_trash => \@trash,
37 ls_mp3 => \@mp3s,
38 };
39  
40 ### $self
41
42
43 0 bless $self, $class;
44  
45  
46  
47
48 0 ▶ $self->is_album or carp("Not deemed album: $abs_path") and return;
Branch: 1 branch
BranchTrueFalseTotal
$self->is_album or carp("Not deemed album: $abs_path") and return 0 0 0
Condition0%0/5
$self->is_album || carp("Not deemed album: $abs_path") && (return)
l!l&&r!l&&!r
000
carp("Not deemed album: $abs_path") and return
!ll
00
MC/DC0%0/2
$self->is_album || carp("Not deemed album: $abs_path") && (return)
$self->is_album carp("Not deemed album: $abs_path")
Truth table0%0/3
A || B
A= $self->is_albumB= carp("Not deemed album: $abs_path")
ABresult
1X1
011
000
49  
50 0 return $self;
51 }
52  
53  
54 0 ▶sub ls_mp3_percent {
Subroutine ls_mp3_percent: not called CC=4 SCAR=30.0
Pod documented
55 0 my $self = shift;
56  
57 0 ▶ my $total_files = $self->ls_count || 0;
Condition0%0/2
$self->ls_count || 0
l!l
00
MC/DC0%0/1
$self->ls_count || 0
$self->ls_count
Truth table0%0/2
A
A= $self->ls_count
Aresult
11
00
58 0 ▶ my $total_mp3 = $self->ls_mp3_count || 0;
Condition0%0/2
$self->ls_mp3_count || 0
l!l
00
MC/DC0%0/1
$self->ls_mp3_count || 0
$self->ls_mp3_count
Truth table0%0/2
A
A= $self->ls_mp3_count
Aresult
11
00
59 0 ▶ $total_mp3 or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$total_mp3 or return 0 0 0 0
60
61 #debug("$total_files $total_mp3");
62  
63 0 int( ($total_mp3 * 100 ) / $total_files );
64 }
65  
66  
67 0 ▶sub is_album { ($_[0]->ls_mp3_percent) > 50 ? 1 : 0 }
Subroutine is_album: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->ls_mp3_percent > 50 ? : 0 0 0
68  
69 0 ▶sub empty_trash {
Subroutine empty_trash: not called CC=3 SCAR=24.8
Pod documented
70 0 ▶ $_[0]->ls_trash_count or warn("Nothing in trash.\n") and return;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->ls_trash_count or warn "Nothing in trash.\n" and return 0 0 0
Condition0%0/5
$_[0]->ls_trash_count || warn("Nothing in trash.\n") && (return)
l!l&&r!l&&!r
000
warn "Nothing in trash.\n" and return
!ll
00
MC/DC0%0/2
$_[0]->ls_trash_count || warn("Nothing in trash.\n") && (return)
$_[0]->ls_trash_count warn "Nothing in trash.\n"
Truth table0%0/3
A || B
A= $_[0]->ls_trash_countB= warn "Nothing in trash.\n"
ABresult
1X1
011
000
71 0 unlink @{$_[0]->ls_trash};
72 0 1;
73 }
74  
75  
76 # paths
77 #
78 0 ▶sub rel_path_suggested {
Subroutine rel_path_suggested: not called CC=3 SCAR=24.8
Pod undocumented
79 0 my $self = shift;
80 0 ▶ my $artist = $self->artist or return;
Branch: 1 branch
BranchTrueFalseTotal
my $artist = $self->artist or return 0 0 0
81 0 ▶ my $album = $self->album or return;
Branch: 1 branch
BranchTrueFalseTotal
my $album = $self->album or return 0 0 0
82 0 "$artist/$album";
83 }
84  
85 0 ▶sub abs_path_suggested {
Subroutine abs_path_suggested: not called CC=2 SCAR=17.9
Pod undocumented
86 0 my $self = shift;
87 0 ▶ my $rel = $self->rel_path_suggested or return;
Branch: 1 branch
BranchTrueFalseTotal
my $rel = $self->rel_path_suggested or return 0 0 0
88 0 $self->abs_music .'/'.$rel;
89 }
90  
91 0 ▶sub abs_path_suggested_exists {
Subroutine abs_path_suggested_exists: not called CC=3 SCAR=24.8
Pod undocumented
92 0 my $self = shift;
93 0 ▶ my $abs = $self->abs_path_suggested or die;
Branch: 1 branch
BranchTrueFalseTotal
my $abs = $self->abs_path_suggested or die 0 0 0
94 0 ▶ -e $abs ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
-e $abs ? : 0 0 0
95 }
96  
97 0 ▶sub abs_path_suggested_require {
Subroutine abs_path_suggested_require: not called CC=4 SCAR=30.0
Pod undocumented
98 0 my $self= shift;
99 0 ▶ $self->abs_path_suggested or return;
Branch: 1 branch
BranchTrueFalseTotal
$self->abs_path_suggested or return 0 0 0
100 0 ▶ $self->abs_path_suggested_exists and return $self->abs_path_suggested;
Branch: 1 branch
BranchTrueFalseTotal
$self->abs_path_suggested_exists and return $self->abs_path_suggested 0 0 0
101 0 require File::Path;
102  
103 0 ▶ File::Path::mkpath($self->abs_path_suggested) or die;
Branch: 1 branch
BranchTrueFalseTotal
File::Path::mkpath($self->abs_path_suggested) or die 0 0 0
104 0 $self->abs_path_suggested;
105 }
106  
107  
108  
109  
110 0 ▶sub refile {
Subroutine refile: not called CC=5 SCAR=34.0
Pod undocumented
111 0 my $self = shift;
112  
113 0 ▶ my $abs_loc = $self->abs_path_suggested_require
Branch: 1 branch
BranchTrueFalseTotal
my $abs_loc = $self->abs_path_suggested_require or $self->errstr(q[Can't refile, cant get abs path suggested require, ] . $self->errstr) and return 0 0 0
Condition0%0/5
(my $abs_loc = $self->abs_path_suggested_require) || $self->errstr(q[Can't refile, cant get abs path suggested require, ] . $self->errstr) && (return)
l!l&&r!l&&!r
000
$self->errstr(q[Can't refile, cant get abs path suggested require, ] . $self->errstr) and return
!ll
00
MC/DC0%0/2
(my $abs_loc = $self->abs_path_suggested_require) || $self->errstr(q[Can't refile, cant get abs path suggested require, ] . $self->errstr) && (return)
(my $abs_loc = $self->abs_path_suggested_require) $self->errstr(q[Can't refile, cant get abs path suggested require, ] . $self->errstr)
Truth table0%0/3
A || B
A= (my $abs_loc = $self->abs_path_suggested_require)B= $self->errstr(q[Can't refile, cant get abs path suggested require, ] . $self->errstr)
ABresult
1X1
011
000
114 or $self->errstr("Can't refile, cant get abs path suggested require, ".$self->errstr )
115 and return;
116  
117
118
119 0 for my $filename ( @{$self->ls} ){
120 0 my $from = $self->abs_path ."/$filename";
121 0 my $to = $abs_loc."/$filename";
122
123  
124 0 ▶ system('mv',$from, $to) ==0
Branch: 1 branch
BranchTrueFalseTotal
system("mv", $from, $to) == 0 or die sprintf("Cannot move %s to %s, $?", $from, $to) 0 0 0
125 or die(sprintf "Cannot move %s to %s, $?", $from,$to);
126 }
127  
128 0 rmdir $self->abs_path;
129  
130 0 $abs_loc;
131 }
132  
133  
134  
135 0 ▶sub artist {
Subroutine artist: not called CC=3 SCAR=24.8
Pod documented
136 0 my($self,$arg)=@_;
137 0 ▶ $arg and $self->{artist} = $arg;
Branch: 1 branch
BranchTrueFalseTotal
$arg and $self->{"artist"} = $arg 0 0 0
138  
139 0 ▶ $self->{artist} ||= $self->_ls_mp3s_aggree_on('artist');
Condition0%0/3
$self->{"artist"} ||= $self->_ls_mp3s_aggree_on("artist")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"artist"} ||= $self->_ls_mp3s_aggree_on("artist")
$self->{"artist"} $self->_ls_mp3s_aggree_on("artist")
Truth table0%0/3
A ||= B
A= $self->{"artist"}B= $self->_ls_mp3s_aggree_on("artist")
ABresult
1X1
011
000
140 }
141  
142  
143  
144 0 ▶sub album {
Subroutine album: not called CC=3 SCAR=24.8
Pod documented
145 0 my($self,$arg)=@_;
146 0 ▶ $arg and $self->{album} = $arg;
Branch: 1 branch
BranchTrueFalseTotal
$arg and $self->{"album"} = $arg 0 0 0
147  
148 0 ▶ $self->{album} ||= $self->_ls_mp3s_aggree_on('album');
Condition0%0/3
$self->{"album"} ||= $self->_ls_mp3s_aggree_on("album")
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"album"} ||= $self->_ls_mp3s_aggree_on("album")
$self->{"album"} $self->_ls_mp3s_aggree_on("album")
Truth table0%0/3
A ||= B
A= $self->{"album"}B= $self->_ls_mp3s_aggree_on("album")
ABresult
1X1
011
000
149 }
150  
151  
152 0 ▶sub _ls_mp3s_aggree_on {
Subroutine _ls_mp3s_aggree_on: not called CC=12 SCAR=48.8
153 0 my ($self,$param) = @_;
154 6 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
155  
156 0 my $suggested;
157 0 my $x=0;
158 0 for ( @{$self->ls_mp3} ){
159 0 my $abs = $self->abs_path.'/'.$_;
160 0 debug("consolidating with : $abs");
161 0 ▶ my $a = $self->file($abs)
Branch: 1 branch
BranchTrueFalseTotal
my $a = $self->file($abs) or warn "cant instance $abs" and next 0 0 0
Condition0%0/5
(my $a = $self->file($abs)) || warn("cant instance $abs") && (next)
l!l&&r!l&&!r
000
warn "cant instance $abs" and next
!ll
00
MC/DC0%0/2
(my $a = $self->file($abs)) || warn("cant instance $abs") && (next)
(my $a = $self->file($abs)) warn "cant instance $abs"
Truth table0%0/3
A || B
A= (my $a = $self->file($abs))B= warn "cant instance $abs"
ABresult
1X1
011
000
162 or warn("cant instance $abs")
163 and next;
164  
165 0 ▶ $a->is_mp3
Branch: 1 branch
BranchTrueFalseTotal
$a->is_mp3 or debug("not mp3") and next 0 0 0
Condition0%0/5
$a->is_mp3 || debug('not mp3') && (next)
l!l&&r!l&&!r
000
debug("not mp3") and next
!ll
00
MC/DC0%0/2
$a->is_mp3 || debug('not mp3') && (next)
$a->is_mp3 debug("not mp3")
Truth table0%0/3
A || B
A= $a->is_mp3B= debug("not mp3")
ABresult
1X1
011
000
166 or debug("not mp3") and next;
167 0 ▶ my $got = $a->$param or next;
Branch: 1 branch
BranchTrueFalseTotal
my $got = $a->$param or next 0 0 0
168 0 ▶ $suggested ||= $got;
Condition0%0/3
$suggested ||= $got
l!l&&r!l&&!r
000
MC/DC0%0/2
$suggested ||= $got
$suggested $got
Truth table0%0/3
A ||= B
A= $suggestedB= $got
ABresult
1X1
011
000
169 0 $x++;
170  
171 0 ▶ if($suggested){
Branch: 1 branch
BranchTrueFalseTotal
if ($suggested) 0 0 0
172 0 ▶ $suggested eq $got
Branch: 1 branch
BranchTrueFalseTotal
$suggested eq $got or $self->errstr("Cant figure out '${param}', $suggested not same as $got for $abs") and return 0 0 0
Condition0%0/5
$suggested eq $got || $self->errstr("Cant figure out '${param}', $suggested not same as $got for $abs") && (return)
l!l&&r!l&&!r
000
$self->errstr("Cant figure out '${param}', $suggested not same as $got for $abs") and return
!ll
00
MC/DC0%0/2
$suggested eq $got || $self->errstr("Cant figure out '${param}', $suggested not same as $got for $abs") && (return)
$suggested eq $got $self->errstr("Cant figure out '${param}', $suggested not same as $got for $abs")
Truth table0%0/3
A || B
A= $suggested eq $gotB= $self->errstr("Cant figure out '${param}', $suggested not same as $got for $abs")
ABresult
1X1
011
000
173 or $self->errstr("Cant figure out '$param', $suggested not same as $got for $abs")
174 and return;
175 }
176 }
177  
178 0 ▶ $suggested or $self->errstr("Cant consolidate '$param' in $x files");
Branch: 1 branch
BranchTrueFalseTotal
$suggested or $self->errstr("Cant consolidate '${param}' in $x files") 0 0 0
179  
180 0 $suggested;
181 }
182  
183 0 ▶sub file {
Subroutine file: not called CC=5 SCAR=34.0
Pod undocumented
184 0 my ($self,$_path) = @_;
185 0 ▶ my $abs = Cwd::abs_path($_path) or die;
Branch: 1 branch
BranchTrueFalseTotal
my $abs = Cwd::abs_path($_path) or die 0 0 0
186 0 ▶ -f $abs or die;
Branch: 1 branch
BranchTrueFalseTotal
-f $abs or die 0 0 0
187 0 ▶ ($self->{file}->{$abs} ||= Astroboy::AlbumFile->new( $abs )) or die;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"file"}{$abs} ||= "Astroboy::AlbumFile"->new($abs) or die 0 0 0
Condition0%0/3
$self->{"file"}{$abs} ||= "Astroboy::AlbumFile"->new($abs)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"file"}{$abs} ||= "Astroboy::AlbumFile"->new($abs)
$self->{"file"}{$abs} "Astroboy::AlbumFile"->new($abs)
Truth table0%0/3
A ||= B
A= $self->{"file"}{$abs}B= "Astroboy::AlbumFile"->new($abs)
ABresult
1X1
011
000
188 }
189  
190  
191  
192  
193 6 1;
194  
195 __END__
« lib/Astroboy/AlbumFile.pm ↑ Summary lib/Astroboy.pm »