| Acme-PlayCode documentation | Contained in the Acme-PlayCode distribution. |
Acme::PlayCode::Plugin::PrintComma - Play code with printing comma
use Acme::PlayCode;
my $app = new Acme::PlayCode;
$app->load_plugin('PrintComma');
my $played_code = $app->play( $code );
# or
my $played_code = $app->play( $filename );
# or
$app->play( $filename, { rewrite_file => 1 } ); # override $filename with played code
print "a " . "print 'a' . 'b'" . "c\n";
becomes
print "a ", "print 'a' . 'b'", "c\n";
Fayland Lam, <fayland at gmail.com>
Copyright 2008 Fayland Lam, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Acme-PlayCode documentation | Contained in the Acme-PlayCode distribution. |
package Acme::PlayCode::Plugin::PrintComma; use Moose::Role; our $VERSION = '0.10'; our $AUTHORITY = 'cpan:FAYLAND'; use vars qw/$printcomma_start/; around 'do_with_token' => sub { my $orig = shift; my $self = shift; my ( $token ) = @_; my $token_flag = $self->token_flag; my @tokens = $self->tokens; $printcomma_start = 0 unless ( defined $printcomma_start ); if ( $token->isa('PPI::Token::Word') and $token->content eq 'print' ) { $printcomma_start = 1; } elsif ( $token->isa('PPI::Token::Structure') ) { $printcomma_start = 0; } elsif ( $printcomma_start and $token->isa('PPI::Token::Operator') and $token->content eq '.' ) { if ( $tokens[$token_flag - 1]->isa('PPI::Token::Whitespace') ) { $self->output->[-1] = 'Acme::PlayCode::!@#$%^&*()_+'; } return ','; } $orig->($self, @_); }; no Moose::Role; 1; __END__