When I use "$module->prune( 'PPI::Token::Whitespace' );" and save the results in $file is there an ease way back to working code for the saved code? I tried "Perl::Tidy" and it looks much better after this but id does not fix all.
#!/usr/bin/env perl
use warnings;
use 5.012;
use PPI;
my $file = 'my_file.pm';
my $module = PPI::Document->new( $file );
$module->prune( 'PPI::Token::Pod' );
$module->prune( 'PPI::Token::Comment' );
$module->prune( 'PPI::Token::Whitespace' );
# ...
# ...
$module->save( $file ) or die $!;
edit:
I am no longer able to reconstruct my code that I had in the first place. With prune-whitespace enabled I could use something like this
$a = $module->find( sub {
$_[1]->isa('PPI::Statement') and
$_[1]->content eq q(if($@){$have_Term_ReadKey=0;$have_Term_Size=1;eval'require "Term/Size.pm"';if($@){$have_Term_Size=0;}})
});
instead of
$a = $module->find( sub {
$_[1]->isa('PPI::Statement') and
$_[1]->schild(0)->content eq q(if) and
$_[1]->schild(1)->isa('PPI::Something') and
...
...
});
to find a point to append something. But know after retrying I think it can not work (apart from the fact, that I can not restore the code without withespaces).