blib/lib/Code/TidyAll/Plugin/PerlTidy.pm

filter: Statementstmt 100% 30 / 30 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 93.7% 45 / 48 CC 6 SCAR 12.7
CC
6
Cov
92%
transform_source
6.1
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« bin/tidyall ↑ Summary blib/lib/Code/TidyAll/Plugin/JSLint.pm »
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.83';
14  
15 sub transform_source {
16 6 ▶ my ( $self, $source ) = @_;
Subroutine transform_source: called CC=6 SCAR=18.1
Pod documented
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
BranchTrueFalseTotal
if $Perl::Tidy::VERSION > 20220101 6 0 6
39  
40 $output = capture_merged {
41 6 ▶ $error_flag = Perl::Tidy::perltidy(
Subroutine __ANON__: called CC=1 SCAR=0.0
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
BranchTrueFalseTotal
if $stderr 1 5 6
50 5 ▶ die $errorfile if $errorfile;
Branch: 1 branch
BranchTrueFalseTotal
if $errorfile 1 4 5
51 4 ▶ die $output if $error_flag;
Branch: 1 branch
BranchTrueFalseTotal
if $error_flag 0 4 4
52 4 ▶ print STDERR $output if defined($output);
Branch: 1 branch
BranchTrueFalseTotal
if defined $output 4 0 4
53 4 return $destination;
54 }
55  
56 1 1;
57  
58 # ABSTRACT: Use perltidy with tidyall
59  
60 __END__
61  
62 =pod
63  
64 =encoding UTF-8
65  
66 =head1 NAME
67  
68 Code::TidyAll::Plugin::PerlTidy - Use perltidy with tidyall
69  
70 =head1 VERSION
71  
72 version 0.83
73  
74 =head1 SYNOPSIS
75  
76 # In configuration:
77  
78 ; Configure in-line
79 ;
80 [PerlTidy]
81 select = lib/**/*.pm
82 argv = --noll
83  
84 ; or refer to a .perltidyrc in the same directory
85 ;
86 [PerlTidy]
87 select = lib/**/*.pm
88 argv = --profile=$ROOT/.perltidyrc
89  
90 =head1 DESCRIPTION
91  
92 Runs L<perltidy>, a Perl tidier.
93  
94 =head1 INSTALLATION
95  
96 Install perltidy from CPAN.
97  
98 cpanm perltidy
99  
100 =head1 CONFIGURATION
101  
102 This plugin accepts the following configuration options:
103  
104 =head2 argv
105  
106 Arguments to pass to C<perltidy>.
107  
108 If you are using C<Perl::Tidy> version 20220101 or newer, than the
109 C<--encode-output-strings> flag will be appended to whatever you supply. In
110 this case, you should ensure that you are I<not> passing a
111 C<--character-encoding> (C<-enc>) or C<-utf8> flag to perltidy as well.
112  
113 =head1 SUPPORT
114  
115 Bugs may be submitted at L<https://github.com/houseabsolute/perl-code-tidyall/issues>.
116  
117 =head1 SOURCE
118  
119 The source code repository for Code-TidyAll can be found at L<https://github.com/houseabsolute/perl-code-tidyall>.
120  
121 =head1 AUTHORS
122  
123 =over 4
124  
125 =item *
126  
127 Jonathan Swartz <swartz@pobox.com>
128  
129 =item *
130  
131 Dave Rolsky <autarch@urth.org>
132  
133 =back
134  
135 =head1 COPYRIGHT AND LICENSE
136  
137 This software is copyright (c) 2011 - 2022 by Jonathan Swartz.
138  
139 This is free software; you can redistribute it and/or modify it under
140 the same terms as the Perl 5 programming language system itself.
141  
142 The full text of the license can be found in the
143 F<LICENSE> file included with this distribution.
144  
145 =cut
« bin/tidyall ↑ Summary blib/lib/Code/TidyAll/Plugin/JSLint.pm »