File Coverage

blib/lib/App/EditorTools/Command/RenameVariable.pm
Criterion Covered Total %
statement 21 21 100.0
branch 1 2 50.0
condition n/a
subroutine 6 6 100.0
pod 3 3 100.0
total 31 32 96.8


line stmt bran cond sub pod time code
1             package App::EditorTools::Command::RenameVariable;
2              
3             # ABSTRACT: Lexically Rename a Variable
4              
5 7     7   5983 use strict;
  7         15  
  7         230  
6 7     7   34 use warnings;
  7         15  
  7         255  
7              
8 7     7   38 use App::EditorTools -command;
  7         12  
  7         48  
9              
10             our $VERSION = '1.00';
11              
12             sub opt_spec {
13             return (
14 1     1 1 40572 [ "line|l=s", "Line number of the start of variable to replace", ],
15             [ "column|c=s", "Column number of the start of variable to replace", ],
16             [ "replacement|r=s", "The new variable name (without sigil)", ],
17             );
18             }
19              
20             sub validate_args {
21 1     1 1 1286 my ( $self, $opt, $args ) = @_;
22 1         4 for (qw(line column replacement)) {
23 3 50       18 $self->usage_error("Arg $_ is required") unless $opt->{$_};
24             }
25 1         4 return 1;
26             }
27              
28             sub execute {
29 1     1 1 6 my ( $self, $opt, $arg ) = @_;
30              
31 1         3 my $doc_as_str = eval { local $/ = undef; };
  1         6  
  1         13  
32              
33 1         1075 require PPIx::EditorTools::RenameVariable;
34 1         162895 print PPIx::EditorTools::RenameVariable->new->rename(
35             code => $doc_as_str,
36             column => $opt->{column},
37             line => $opt->{line},
38             replacement => $opt->{replacement},
39             )->code;
40 1         17987 return;
41             }
42              
43             1;
44              
45             __END__