blib/lib/Mason/Plugin/TidyObjectFiles/Interp.pm untested

filter: Statementstmt 0.0% 0 / 25 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 34 CC 1 SCAR 6.9
CC
1
Cov
0%
prefilter
2.0
postfilter
2.0
BEGIN
2.0
CRAP 2.0
1 package Mason::Plugin::TidyObjectFiles::Interp;
2 $Mason::Plugin::TidyObjectFiles::Interp::VERSION = '2.24';
3 use Mason::PluginRole;
4 use Perl::Tidy;
5  
6 has 'tidy_options' => ( is => 'ro' );
7  
8 around 'write_object_file' => sub {
9 my ( $orig, $self, $object_file, $object_contents ) = @_;
10  
11 my $argv = $self->tidy_options || '';
12 my $tidied_object_contents;
13 Perl::Tidy::perltidy(
14 'perltidyrc' => '/dev/null',
15 source => \$object_contents,
16 destination => \$tidied_object_contents,
17 prefilter => sub { $self->prefilter( $_[0] ) },
18 postfilter => sub { $self->postfilter( $_[0] ) },
19 argv => $argv
20 );
21 $tidied_object_contents =~ s/^\s*(\#line .*)/$1/mg;
22 $self->$orig( $object_file, $tidied_object_contents );
23 };
24  
25 sub prefilter {
26 my $self = shift;
27 $_ = $_[0];
28  
29 # Turn method into sub
30 s/^method (.*)/sub $1 \#__METHOD/gm;
31  
32 return $_;
33 }
34  
35 sub postfilter {
36 my $self = shift;
37 $_ = $_[0];
38  
39 # Turn sub back into method
40 s/^sub (.*?)\s* \#__METHOD/method $1/gm;
41  
42 return $_;
43 }
44  
45 1;