/
RenamePackageFromPath.pm
64 lines (42 loc) · 1.54 KB
/
RenamePackageFromPath.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package App::EditorTools::Command::RenamePackageFromPath;
use strict;
use warnings;
use Path::Class;
use App::EditorTools -command;
our $VERSION = '0.16';
sub opt_spec {
return ( [ "filename|f=s", "The filename and path of the package", ] );
}
sub validate_args {
my ( $self, $opt, $args ) = @_;
$self->usage_error("Filename is required") unless $opt->{filename};
# If we are dealing with a real file, see if we can clean up the
# path. This let's us work on files under a symlink
# (ie, M/ -> lib/App/Model), but rename them correctly.
if( -f $opt->{filename} ){
my $real_name = file( $opt->{filename} )->resolve;
$opt->{filename} = $real_name if defined $real_name;
}
return 1;
}
sub execute {
my ( $self, $opt, $arg ) = @_;
my $doc_as_str = eval { local $/ = undef; <STDIN> };
require PPIx::EditorTools::RenamePackageFromPath;
print PPIx::EditorTools::RenamePackageFromPath->new->rename(
code => $doc_as_str,
filename => $opt->{filename} )->code;
return;
}
1;
=head1 NAME
App::EditorTools::Command::RenamePackageFromPath - Rename the Package Based on the Path of the File
=head1 DESCRIPTION
See L<App::EditorTools> for documentation.
=head1 AUTHOR
Mark Grimes, E<lt>mgrimes@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2010 by Mark Grimes
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.2 or,
at your option, any later version of Perl 5 you may have available.