| 1 | package Code::TidyAll::Plugin::PerlTidy; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Capture::Tiny qw(capture_merged); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Perl::Tidy; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | extends 'Code::TidyAll::Plugin'; | |||||||||
| 12 | |||||||||||
| 13 | 1 | our $VERSION = '0.85'; | |||||||||
| 14 | |||||||||||
| 15 | 6 | ▶ | sub transform_source { | ||||||||
|
Subroutine
transform_source: called CC=6 SCAR=18.1
Pod
documented
| |||||||||||
| 16 | 6 | my ( $self, $source ) = @_; | |||||||||
| 17 | |||||||||||
| 18 | # This bit of insanity is needed because if some other code calls | ||||||||||
| 19 | # Getopt::Long::Configure() to change some options, then everything can go | ||||||||||
| 20 | # to hell. Internally perltidy() tries to use Getopt::Long without | ||||||||||
| 21 | # resetting the configuration defaults, leading to very confusing | ||||||||||
| 22 | # errors. See https://rt.cpan.org/Ticket/Display.html?id=118558 | ||||||||||
| 23 | 6 | Getopt::Long::ConfigDefaults(); | |||||||||
| 24 | |||||||||||
| 25 | # perltidy reports errors in two different ways. | ||||||||||
| 26 | # Argument/profile errors are output and an error_flag is returned. | ||||||||||
| 27 | # Syntax errors are sent to errorfile or stderr, depending on the | ||||||||||
| 28 | # the setting of -se/-nse (aka --standard-error-output). These flags | ||||||||||
| 29 | # might be hidden in other bundles, e.g. -pbp. Be defensive and | ||||||||||
| 30 | # check both. | ||||||||||
| 31 | 6 | my ( $output, $error_flag, $errorfile, $stderr, $destination ); | |||||||||
| 32 | |||||||||||
| 33 | # Add --encode-output-strings (-eos) for PT releases in 2022 and later to | ||||||||||
| 34 | # tell perltidy that we want encoded character strings returned. See | ||||||||||
| 35 | # https://github.com/houseabsolute/perl-code-tidyall/issues/84 | ||||||||||
| 36 | # https://github.com/perltidy/perltidy/issues/83 | ||||||||||
| 37 | 6 | my $argv = $self->argv; | |||||||||
| 38 | 6 | ▶ | $argv .= ' --encode-output-strings' if $Perl::Tidy::VERSION > 20220101; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | |||||||||||
| 40 | 6 | ▶ | $output = capture_merged { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 41 | 6 | $error_flag = Perl::Tidy::perltidy( | |||||||||
| 42 | argv => $self->argv, | ||||||||||
| 43 | source => \$source, | ||||||||||
| 44 | destination => \$destination, | ||||||||||
| 45 | stderr => \$stderr, | ||||||||||
| 46 | errorfile => \$errorfile | ||||||||||
| 47 | ); | ||||||||||
| 48 | 6 | }; | |||||||||
| 49 | 6 | ▶ | die $stderr if $stderr; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 5 | ▶ | die $errorfile if $errorfile; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | 4 | ▶ | die $output if $error_flag; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 4 | ▶ | print STDERR $output if defined($output); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 4 | return $destination; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 1 | 1; | |||||||||
| 57 | |||||||||||
| 58 | # ABSTRACT: Use perltidy with tidyall | ||||||||||
| 59 | |||||||||||
| 60 | __END__ | ||||||||||