| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package PPIx::EditorTools::RenamePackageFromPath; | 
| 2 |  |  |  |  |  |  | our $AUTHORITY = 'cpan:YANICK'; | 
| 3 |  |  |  |  |  |  | # ABSTRACT: Change the package name based on the files path | 
| 4 |  |  |  |  |  |  | $PPIx::EditorTools::RenamePackageFromPath::VERSION = '0.21'; | 
| 5 | 2 |  |  | 2 |  | 169121 | use 5.008; | 
|  | 2 |  |  |  |  | 11 |  | 
| 6 | 2 |  |  | 2 |  | 7 | use strict; | 
|  | 2 |  |  |  |  | 12 |  | 
|  | 2 |  |  |  |  | 32 |  | 
| 7 | 2 |  |  | 2 |  | 8 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 45 |  | 
| 8 | 2 |  |  | 2 |  | 8 | use Carp; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 109 |  | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 2 |  |  |  |  | 11 | use Class::XSAccessor accessors => { | 
| 11 |  |  |  |  |  |  | 'replacement' => 'replacement', | 
| 12 |  |  |  |  |  |  | 'filename'    => 'filename', | 
| 13 | 2 |  |  | 2 |  | 421 | }; | 
|  | 2 |  |  |  |  | 1825 |  | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 2 |  |  | 2 |  | 416 | use base 'PPIx::EditorTools'; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 457 |  | 
| 16 | 2 |  |  | 2 |  | 315 | use PPIx::EditorTools::RenamePackage; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 36 |  | 
| 17 | 2 |  |  | 2 |  | 8 | use Carp; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 78 |  | 
| 18 | 2 |  |  | 2 |  | 10 | use File::Spec; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 102 |  | 
| 19 | 2 |  |  | 2 |  | 21 | use File::Basename; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 556 |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub rename { | 
| 23 | 4 |  |  | 4 | 1 | 2734 | my ( $self, %args ) = @_; | 
| 24 | 4 |  |  |  |  | 42 | $self->process_doc(%args); | 
| 25 | 4 |  | 33 |  |  | 14 | my $path = $args{filename} || croak "filename required"; | 
| 26 |  |  |  |  |  |  |  | 
| 27 | 4 |  |  |  |  | 121 | my $dir = dirname $path; | 
| 28 | 4 |  |  |  |  | 193 | my $file = basename $path, qw/.pm .PM .Pm/; | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | my @directories = | 
| 31 | 4 | 100 |  |  |  | 110 | grep { $_ && !/^\.$/ } File::Spec->splitdir( File::Spec->rel2abs($dir) ); | 
|  | 33 |  |  |  |  | 93 |  | 
| 32 | 4 |  |  |  |  | 8 | my $replacement; | 
| 33 | 4 | 100 |  |  |  | 6 | if ( grep {/^lib$/} @directories ) { | 
|  | 29 |  |  |  |  | 46 |  | 
| 34 | 3 |  |  |  |  | 15 | while ( shift(@directories) !~ /^lib$/ ) { } | 
| 35 |  |  |  |  |  |  | } else { | 
| 36 | 1 | 50 |  |  |  | 5 | @directories = grep { $_ && !/^\.$/ } File::Spec->splitdir($dir); | 
|  | 3 |  |  |  |  | 13 |  | 
| 37 |  |  |  |  |  |  | } | 
| 38 | 4 |  |  |  |  | 10 | $replacement = join( '::', @directories, $file ); | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 4 |  |  |  |  | 34 | return PPIx::EditorTools::RenamePackage->new( ppi => $self->ppi )->rename( replacement => $replacement ); | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | 1; | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | __END__ |