blib/lib/PPIx/EditorTools/RenamePackageFromPath.pm

filter: Statementstmt 100% 47 / 47 Branchbran 100% 4 / 4 Conditioncond 62.5% 5 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 92.1% 70 / 76 CC 6 SCAR 10.6
CC
6
Cov
95%
rename
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.9
« blib/lib/PPIx/EditorTools/RenamePackage.pm ↑ Summary blib/lib/PPIx/EditorTools/ReturnObject.pm »
1 package PPIx::EditorTools::RenamePackageFromPath;
2 3 our $AUTHORITY = 'cpan:YANICK';
3 # ABSTRACT: Change the package name based on the files path
4 3 $PPIx::EditorTools::RenamePackageFromPath::VERSION = '0.21';
5 3 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use Class::XSAccessor accessors => {
Subroutine BEGIN: called CC=1 SCAR=0.0
11 'replacement' => 'replacement',
12 'filename' => 'filename',
13 3 };
14  
15 3 ▶use base 'PPIx::EditorTools';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use PPIx::EditorTools::RenamePackage;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21  
22 4 ▶sub rename {
Subroutine rename: called CC=6 SCAR=18.0
Pod documented
23 4 my ( $self, %args ) = @_;
24 4 $self->process_doc(%args);
25 4 ▶ my $path = $args{filename} || croak "filename required";
Condition50%1/2
$args{'filename'} || croak('filename required')
l!l
40
MC/DC0%0/1
$args{'filename'} || croak('filename required')
$args{'filename'}
Truth table50%1/2
A
A= $args{'filename'}
Aresult
11
00
26  
27 4 my $dir = dirname $path;
28 4 my $file = basename $path, qw/.pm .PM .Pm/;
29  
30 my @directories =
31 4 ▶ grep { $_ && !/^\.$/ } File::Spec->splitdir( File::Spec->rel2abs($dir) );
Condition66%2/3
$_ && !/^\.$/
!ll&&!rl&&r
4033
MC/DC50%1/2
$_ && !/^\.$/
$_ !/^\.$/
Truth table66%2/3
A && not(B)
A= $_B= !/^\.$/
ABresult
0X0
100
111
32 4 my $replacement;
33 4 ▶ if ( grep {/^lib$/} @directories ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {/^lib$/;} @directories) { } 3 1 4
34 3 ▶ while ( shift(@directories) !~ /^lib$/ ) { }
Branch: 1 branch
BranchTrueFalseTotal
unless (shift(@directories) =~ /^lib$/) 15 3 18
35 } else {
36 1 ▶ @directories = grep { $_ && !/^\.$/ } File::Spec->splitdir($dir);
Condition66%2/3
$_ && !/^\.$/
!ll&&!rl&&r
012
MC/DC50%1/2
$_ && !/^\.$/
$_ !/^\.$/
Truth table66%2/3
A && not(B)
A= $_B= !/^\.$/
ABresult
0X0
100
111
37 }
38 4 $replacement = join( '::', @directories, $file );
39  
40 4 return PPIx::EditorTools::RenamePackage->new( ppi => $self->ppi )->rename( replacement => $replacement );
41  
42 }
43  
44 3 1;
45  
46 __END__
« blib/lib/PPIx/EditorTools/RenamePackage.pm ↑ Summary blib/lib/PPIx/EditorTools/ReturnObject.pm »