File Coverage

lib/App/PRT/Command/IntroduceVariables.pm
Criterion Covered Total %
statement 30 30 100.0
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 0 4 0.0
total 41 46 89.1


line stmt bran cond sub pod time code
1             package App::PRT::Command::IntroduceVariables;
2 2     2   1528 use strict;
  2         3  
  2         49  
3 2     2   6 use warnings;
  2         3  
  2         42  
4 2     2   420 use PPI;
  2         82243  
  2         114  
5              
6             sub new {
7 4     4 0 9499 my ($class) = @_;
8 4         21 bless {}, $class;
9             }
10              
11             sub parse_arguments {
12 1     1 0 2 my ($self, @arguments) = @_;
13 2     2   1008 use Data::Dumper;
  2         8574  
  2         348  
14 1         31 @arguments;
15             }
16              
17             sub execute {
18 1     1 0 332 my ($self, $file, $out) = @_;
19              
20 1         3 my $variables = $self->collect_variables($file);
21 1         430 for my $variable (@$variables) {
22 6         51 say $out $variable;
23             }
24             }
25              
26             sub collect_variables {
27 2     2 0 4 my ($self, $file) = @_;
28 2         8 my $document = PPI::Document->new($file);
29              
30 2         15260 my $knowns = {};
31 2         4 my $variables = [];
32 2         7 my $tokens = $document->find('PPI::Token::Symbol');
33 2 50       4653 return [] unless $tokens;
34              
35 2         3 for my $token (@$tokens) {
36 20 100       49 next if $knowns->{$token}++;
37              
38 12         40 push @$variables, $token->content;
39             }
40              
41 2         14 $variables;
42             }
43              
44             1;