| 1 | package Dist::Zilla::Plugin::PerlTidy; | ||||||||||||||||||||||||||||
| 2 | 4 | $Dist::Zilla::Plugin::PerlTidy::VERSION = '0.21'; | |||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | # ABSTRACT: PerlTidy in Dist::Zilla | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 4 | with( | |||||||||||||||||||||||||||
| 8 | 'Dist::Zilla::Role::FileMunger', | ||||||||||||||||||||||||||||
| 9 | 'Dist::Zilla::Role::FileFinderUser' => { | ||||||||||||||||||||||||||||
| 10 | default_finders => [ ':InstallModules', ':ExecFiles', ':TestFiles' ], | ||||||||||||||||||||||||||||
| 11 | }, | ||||||||||||||||||||||||||||
| 12 | ); | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 4 | has 'perltidyrc' => ( is => 'ro' ); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub munge_files { | ||||||||||||||||||||||||||
|
Subroutine
munge_files: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 0 | $self->munge_file($_) for @{ $self->found_files }; | |||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub munge_file { | ||||||||||||||||||||||||||
|
Subroutine
munge_file: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 23 | 0 | my ( $self, $file ) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | return $self->_munge_perl($file) if $file->name =~ /\.(?:pm|pl|t)$/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | return if -B $file->name; # do not try to read binary file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return $self->_munge_perl($file) if $file->content =~ /^#!.*\bperl\b/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | return; | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub _munge_perl { | ||||||||||||||||||||||||||
|
Subroutine
_munge_perl: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||
| 32 | 0 | my ( $self, $file ) = @_; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | return if ref($file) eq 'Dist::Zilla::File::FromCode'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | return | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if $file->name | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file->name and $file->name eq "t/00-compile.t"
MC/DC0%0/2
$file->name and $file->name eq "t/00-compile.t"
$file->name
$file->name eq "t/00-compile.t"
Truth table0%0/3
A and B
A= $file->nameB= $file->name eq "t/00-compile.t"
| |||||||||||||||||||||||||||||
| 37 | and $file->name eq 't/00-compile.t' | ||||||||||||||||||||||||||||
| 38 | ; # simply skip Dist::Zilla::Plugin::Test::Compile (RT 88601) | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $source = $file->content; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | my $perltidyrc; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ( defined $self->perltidyrc ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( -r $self->perltidyrc ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | $perltidyrc = $self->perltidyrc; | |||||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||||
| 47 | 0 | $self->log_fatal( | |||||||||||||||||||||||||||
| 48 | [ "specified perltidyrc is not readable: %s", $perltidyrc ] ); | ||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # make Perl::Tidy happy | ||||||||||||||||||||||||||||
| 53 | 0 | local @ARGV = (); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my $destination; | |||||||||||||||||||||||||||
| 56 | 0 | require Perl::Tidy; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | Perl::Tidy::perltidy( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | source => \$source, | ||||||||||||||||||||||||||||
| 59 | destination => \$destination, | ||||||||||||||||||||||||||||
| 60 | ( $perltidyrc ? ( perltidyrc => $perltidyrc ) : () ), | ||||||||||||||||||||||||||||
| 61 | ); | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | $file->content($destination); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 67 | 4 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 4 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||