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
|
package App::PRT::Command::IntroduceVariables;
use strict;
use warnings;
use PPI;
sub new {
my ($class) = @_;
bless {}, $class;
}
sub parse_arguments {
my ($self, @arguments) = @_;
use Data::Dumper;
@arguments;
}
sub execute {
my ($self, $file, $out) = @_;
my $variables = $self->collect_variables($file);
for my $variable (@$variables) {
say $out $variable;
}
}
sub collect_variables {
my ($self, $file) = @_;
my $document = PPI::Document->new($file);
my $knowns = {};
my $variables = [];
my $tokens = $document->find('PPI::Token::Symbol');
return [] unless $tokens;
for my $token (@$tokens) {
next if $knowns->{$token}++;
push @$variables, $token->content;
}
$variables;
}
1;
|