11*Ͱ໋ྩݟ͍ͨ my $document = PPI::Document->new($ARGV[0]); my $statements = $document->find('PPI::Statement'); my $statement_count = @$statements; say "count: $statement_count"; 148݄30༵
11*Ͱ'J[[#V[[Λഁյ͍ͨ͠ use PPI; my $path = $ARGV[0]; my $document = PPI::Document->new($path); my $tokens = $document->find('PPI::Token'); for my $token (@$tokens) { if (ref $token eq 'PPI::Token::Number') { $token->set_content($token->content * 2); } } $document->save("broken-$path"); 148݄30༵
11*Ͱ'J[[#V[[Λഁյ͍ͨ͠ use PPI; my $path = $ARGV[0]; my $document = PPI::Document->new($path); my $tokens = $document->find('PPI::Token'); for my $token (@$tokens) { if (ref $token eq 'PPI::Token::Number') { $token->set_content($token->content * 2); } } $document->save("broken-$path"); ࣈΛݟ͚ͭͨΒ ͱΓ͋͑ͣഒʹ͢Δ 148݄30༵
1FSM$SJUJD1PMJDZ.PEVMFT3FRVJSF&OE8JUI0OF sub violates { my ( $self, $elem, $doc ) = @_; # Last statement should be just "1;" my @significant = grep { _is_code($_) } $doc->schildren(); my $match = $significant[-1]; return if !$match; return if ((ref $match) eq 'PPI::Statement' && $match =~ m{\A 1 \s* ; \z}xms ); # Must be a violation... return $self->violation( $DESC, $EXPL, $match ); } 148݄30༵
ࢦఆ͞ΕͨϑΝΠϧ ॱ൪ʹݟΔ sub replace_all { for my $file (@ARGV) { my $document = PPI::Document->new($file); my $package = $document->find_first( 'PPI::Statement::Package' ); my $package_name = $package->namespace; my $methods = $document->find( 'PPI::Statement::Sub' ); for my $method (@$methods) { my $document = PPI::Document->new($file); ...; } } } 148݄30༵