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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
# Test use of prefilter and postfilter parameters
use strict;
use Carp;
use Perl::Tidy;
use Test;
BEGIN {
plan tests => 1;
}
my $source = <<'ENDS';
use Method::Signatures::Simple;
method foo1 { $self->bar }
# with signature
method foo2($bar, %opts) { $self->bar(reverse $bar) if $opts{rev};
}
# attributes
method foo3 : lvalue { $self->{foo}
}
# change invocant name
method
foo4 ($class: $bar) { $class->bar($bar) }
ENDS
my $expect = <<'ENDE';
use Method::Signatures::Simple;
method foo1 { $self->bar }
# with signature
method foo2 ( $bar, %opts ) {
$self->bar( reverse $bar ) if $opts{rev};
}
# attributes
method foo3 : lvalue {
$self->{foo};
}
# change invocant name
method foo4 ($class: $bar) { $class->bar($bar) }
ENDE
my $output;
my $stderr_string;
my $errorfile_string;
my $err = Perl::Tidy::perltidy(
argv => '-npro', # fix for RT#127679, avoid reading unwanted .perltidyrc
prefilter =>
sub { $_ = $_[0]; s/^\s*method\s+(\w.*)/sub METHOD_$1/gm; return $_ },
postfilter => sub { $_ = $_[0]; s/sub\s+METHOD_/method /gm; return $_ },
source => \$source,
destination => \$output,
stderr => \$stderr_string,
errorfile => \$errorfile_string, # not used when -se flag is set
);
if ( $err || $stderr_string || $errorfile_string ) {
ok(0);
}
else {
ok( $output, $expect );
}
|