| 1 | package Code::TidyAll::Plugin::PerlTidySweet; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Capture::Tiny qw(capture_merged); | ||
| 7 | use Perl::Tidy::Sweetened 1.00; | ||
| 8 | |||
| 9 | use Moo; | ||
| 10 | |||
| 11 | extends 'Code::TidyAll::Plugin'; | ||
| 12 | |||
| 13 | our $VERSION = '0.83'; | ||
| 14 | |||
| 15 | sub transform_source { | ||
| 16 | my ( $self, $source ) = @_; | ||
| 17 | |||
| 18 | # perltidy reports errors in two different ways. | ||
| 19 | # Argument/profile errors are output and an error_flag is returned. | ||
| 20 | # Syntax errors are sent to errorfile or stderr, depending on the | ||
| 21 | # the setting of -se/-nse (aka --standard-error-output). These flags | ||
| 22 | # might be hidden in other bundles, e.g. -pbp. Be defensive and | ||
| 23 | # check both. | ||
| 24 | my ( $output, $error_flag, $errorfile, $stderr, $destination ); | ||
| 25 | $output = capture_merged { | ||
| 26 | $error_flag = Perl::Tidy::Sweetened::perltidy( | ||
| 27 | argv => $self->argv, | ||
| 28 | source => \$source, | ||
| 29 | destination => \$destination, | ||
| 30 | stderr => \$stderr, | ||
| 31 | errorfile => \$errorfile | ||
| 32 | ); | ||
| 33 | }; | ||
| 34 | die $stderr if $stderr; | ||
| 35 | die $errorfile if $errorfile; | ||
| 36 | die $output if $error_flag; | ||
| 37 | print STDERR $output if defined($output); | ||
| 38 | return $destination; | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; | ||
| 42 | |||
| 43 | # ABSTRACT: Use perltidy-sweet with tidyall | ||
| 44 | |||
| 45 | __END__ | ||
| 46 | |||
| 47 | =pod | ||
| 48 | |||
| 49 | =encoding UTF-8 | ||
| 50 | |||
| 51 | =head1 NAME | ||
| 52 | |||
| 53 | Code::TidyAll::Plugin::PerlTidySweet - Use perltidy-sweet with tidyall | ||
| 54 | |||
| 55 | =head1 VERSION | ||
| 56 | |||
| 57 | version 0.83 | ||
| 58 | |||
| 59 | =head1 SYNOPSIS | ||
| 60 | |||
| 61 | # In configuration: | ||
| 62 | |||
| 63 | ; Configure in-line | ||
| 64 | ; | ||
| 65 | [PerlTidySweet] | ||
| 66 | select = lib/**/*.pm | ||
| 67 | argv = --noll | ||
| 68 | |||
| 69 | ; or refer to a .perltidyrc in the same directory | ||
| 70 | ; | ||
| 71 | [PerlTidySweet] | ||
| 72 | select = lib/**/*.pm | ||
| 73 | argv = --profile=$ROOT/.perltidyrc | ||
| 74 | |||
| 75 | =head1 DESCRIPTION | ||
| 76 | |||
| 77 | Runs L<perltidy-sweet>, a Perl tidier based on Perl::Tidy that also supports | ||
| 78 | new syntactic sugar as provided by L<Method::Signature::Simple>, | ||
| 79 | L<MooseX::Method::Signatures> and the p5-mop. | ||
| 80 | |||
| 81 | =head1 INSTALLATION | ||
| 82 | |||
| 83 | Install perltidy-sweet from CPAN. | ||
| 84 | |||
| 85 | cpanm Perl::Tidy::Sweet | ||
| 86 | |||
| 87 | =head1 CONFIGURATION | ||
| 88 | |||
| 89 | This plugin accepts the following configuration options: | ||
| 90 | |||
| 91 | =head2 argv | ||
| 92 | |||
| 93 | Arguments to pass to C<perltidy-sweet>. | ||
| 94 | |||
| 95 | =head1 SUPPORT | ||
| 96 | |||
| 97 | Bugs may be submitted at L<https://github.com/houseabsolute/perl-code-tidyall/issues>. | ||
| 98 | |||
| 99 | =head1 SOURCE | ||
| 100 | |||
| 101 | The source code repository for Code-TidyAll can be found at L<https://github.com/houseabsolute/perl-code-tidyall>. | ||
| 102 | |||
| 103 | =head1 AUTHORS | ||
| 104 | |||
| 105 | =over 4 | ||
| 106 | |||
| 107 | =item * | ||
| 108 | |||
| 109 | Jonathan Swartz <swartz@pobox.com> | ||
| 110 | |||
| 111 | =item * | ||
| 112 | |||
| 113 | Dave Rolsky <autarch@urth.org> | ||
| 114 | |||
| 115 | =back | ||
| 116 | |||
| 117 | =head1 COPYRIGHT AND LICENSE | ||
| 118 | |||
| 119 | This software is copyright (c) 2011 - 2022 by Jonathan Swartz. | ||
| 120 | |||
| 121 | This is free software; you can redistribute it and/or modify it under | ||
| 122 | the same terms as the Perl 5 programming language system itself. | ||
| 123 | |||
| 124 | The full text of the license can be found in the | ||
| 125 | F<LICENSE> file included with this distribution. | ||
| 126 | |||
| 127 | =cut |