File: Interp.pm

package info (click to toggle)
libmason-perl 2.24-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 748 kB
  • sloc: perl: 4,882; makefile: 7
file content (45 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download | duplicates (3)
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
package Mason::Plugin::TidyObjectFiles::Interp;
$Mason::Plugin::TidyObjectFiles::Interp::VERSION = '2.24';
use Mason::PluginRole;
use Perl::Tidy;

has 'tidy_options' => ( is => 'ro' );

around 'write_object_file' => sub {
    my ( $orig, $self, $object_file, $object_contents ) = @_;

    my $argv = $self->tidy_options || '';
    my $tidied_object_contents;
    Perl::Tidy::perltidy(
        'perltidyrc' => '/dev/null',
        source       => \$object_contents,
        destination  => \$tidied_object_contents,
        prefilter    => sub { $self->prefilter( $_[0] ) },
        postfilter   => sub { $self->postfilter( $_[0] ) },
        argv         => $argv
    );
    $tidied_object_contents =~ s/^\s*(\#line .*)/$1/mg;
    $self->$orig( $object_file, $tidied_object_contents );
};

sub prefilter {
    my $self = shift;
    $_ = $_[0];

    # Turn method into sub
    s/^method (.*)/sub $1 \#__METHOD/gm;

    return $_;
}

sub postfilter {
    my $self = shift;
    $_ = $_[0];

    # Turn sub back into method
    s/^sub (.*?)\s* \#__METHOD/method $1/gm;

    return $_;
}

1;