| 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')
MC/DC0%0/1
$args{'filename'} || croak('filename required')
$args{'filename'}
Truth table50%1/2
A
A= $args{'filename'}
| |||||||||||||||||||||
| 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
$_ && !/^\.$/
MC/DC50%1/2
$_ && !/^\.$/
$_
!/^\.$/
Truth table66%2/3
A && not(B)
A= $_B= !/^\.$/
| |||||||||||||||||||||
| 32 | 4 | my $replacement; | |||||||||||||||||||
| 33 | 4 | ▶ | if ( grep {/^lib$/} @directories ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 34 | 3 | ▶ | while ( shift(@directories) !~ /^lib$/ ) { } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | } else { | ||||||||||||||||||||
| 36 | 1 | ▶ | @directories = grep { $_ && !/^\.$/ } File::Spec->splitdir($dir); | ||||||||||||||||||
|
Condition66%2/3
$_ && !/^\.$/
MC/DC50%1/2
$_ && !/^\.$/
$_
!/^\.$/
Truth table66%2/3
A && not(B)
A= $_B= !/^\.$/
| |||||||||||||||||||||
| 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__ | ||||||||||||||||||||