File Coverage

blib/lib/App/EditorTools/Command/IntroduceTemporaryVariable.pm
Criterion Covered Total %
statement 30 30 100.0
branch 4 8 50.0
condition n/a
subroutine 6 6 100.0
pod 3 3 100.0
total 43 47 91.4


line stmt bran cond sub pod time code
1             package App::EditorTools::Command::IntroduceTemporaryVariable;
2              
3             # ABSTRACT: Introduce a Temporary Variable
4              
5 7     7   6552 use strict;
  7         16  
  7         269  
6 7     7   37 use warnings;
  7         11  
  7         230  
7              
8 7     7   34 use App::EditorTools -command;
  7         11  
  7         80  
9              
10             our $VERSION = '1.00';
11              
12             sub opt_spec {
13             return (
14 1     1 1 39583 [ "start_location|s=s", "The line,column of the start" ],
15             [ "end_location|e=s", "The line,column of the end" ],
16             [ "varname|v=s", "The new variable name" ],
17             );
18             }
19              
20             sub validate_args {
21 1     1 1 1234 my ( $self, $opt, $args ) = @_;
22              
23 1 50       12 $self->usage_error("start_location is required")
24             unless $opt->{start_location};
25 1 50       5 $self->usage_error("end_location is required") unless $opt->{end_location};
26              
27 1         4 $opt->{start} = [ grep {/\d+/} split /,/, $opt->{start_location} ];
  2         11  
28 1         6 $opt->{end} = [ grep {/\d+/} split /,/, $opt->{end_location} ];
  2         8  
29              
30 1         9 $self->usage_error("start_location must be ,")
31 1 50       9 unless scalar @{ $opt->{start} } == 2;
32 1         5 $self->usage_error("end_location must be ,")
33 1 50       3 unless scalar @{ $opt->{end} } == 2;
34              
35 1         3 return 1;
36             }
37              
38             sub execute {
39 1     1 1 7 my ( $self, $opt, $arg ) = @_;
40              
41 1         3 my $doc_as_str = eval { local $/ = undef; };
  1         5  
  1         11  
42              
43 1         1111 require PPIx::EditorTools::IntroduceTemporaryVariable;
44 1         192148 my $munged = PPIx::EditorTools::IntroduceTemporaryVariable->new->introduce(
45             code => $doc_as_str,
46             start_location => $opt->{start},
47             end_location => $opt->{end},
48             varname => $opt->{varname},
49             );
50              
51 1         11229 print $munged->code;
52 1         491 return;
53             }
54              
55             1;
56              
57             __END__