Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Adds plugin to support Perl::Tidy::Sweetened #14

Closed
wants to merge 6 commits into from

2 participants

@mvgrimes

Perl::Tidy::Sweetened is a code tidier, built on Perl::Tidy, that
supports the new syntactic sugar for OO and method signatures as
provided by LMethod::Signature::Simple, LMooseX::Method::Signatures
and the p5-mop.

This patch creates a plugin to support Perl::Tidy::Sweetened
under Code::TidyAll.

Thanks,
Mark

@mvgrimes mvgrimes Adds plugin to support Perl::Tidy::Sweetened
Perl::Tidy::Sweetened is a code tidier, built on Perl::Tidy, that
supports the new syntactic sugar for OO and method signatures as
provided by L<Method::Signature::Simple>, L<MooseX::Method::Signatures>
and the p5-mop.
abbd08a
@autarch
Owner

This looks good to me, but I think it'd be better named "perltidysweetened" rather than "perltidier". The latter name is way too close to "perltidy" and doesn't really give any indication of how it's different.

@mvgrimes mvgrimes Renames PerlTidier to PerlTidySweet
- More clearly differentiates from PerlTidy. Thanks to Dave Rolsky for
  the recommendation.
c9d722d
@mvgrimes

Good idea. I went with perltidy-sweet, and patched the pull request.

@autarch autarch commented on the diff
lib/Code/TidyAll/Plugin/PerlTidySweet.pm
@@ -0,0 +1,76 @@
+package Code::TidyAll::Plugin::PerlTidySweet;
@autarch Owner
autarch added a note

You need to add a blank line after the package statement for the benefit of dzil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@autarch
Owner

I'll merge this once Travis passes. I made a comment explaining why it's failing.

lib/Code/TidyAll/t/Plugin/PerlTidier.pm
@@ -0,0 +1,37 @@
+
+package Code::TidyAll::t::Plugin::PerlTidier;
@autarch Owner
autarch added a note

You also need a blank line here to make dzil happy.

BTW, feel free to rebase all the changes together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@autarch
Owner

I finally got the test suite passing in travis (the blead failure is not because of this distro). If you rebase off master and push we can see if your branch passes too.

@autarch
Owner

Looks like you submitted this as a separate PR (you can force push to an existing PR, just so you know). I'll close this one.

@autarch autarch closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 7, 2013
  1. @mvgrimes

    Adds plugin to support Perl::Tidy::Sweetened

    mvgrimes authored
    Perl::Tidy::Sweetened is a code tidier, built on Perl::Tidy, that
    supports the new syntactic sugar for OO and method signatures as
    provided by L<Method::Signature::Simple>, L<MooseX::Method::Signatures>
    and the p5-mop.
Commits on Dec 20, 2014
  1. @mvgrimes

    Renames PerlTidier to PerlTidySweet

    mvgrimes authored
    - More clearly differentiates from PerlTidy. Thanks to Dave Rolsky for
      the recommendation.
Commits on Dec 21, 2014
  1. @mvgrimes
Commits on Dec 23, 2014
  1. @mvgrimes
  2. @mvgrimes
  3. @mvgrimes
This page is out of date. Refresh to see the latest.
View
1  README.md
@@ -127,6 +127,7 @@ You can call this API from your own program instead of executing `tidyall`.
- George Hartzell <georgewh@gene.com>
- Gregory Oschwald <goschwald@maxmind.com>
- Joe Crotty <joe.crotty@returnpath.net>
+- Mark Grimes <mgrimes@cpan.org>
- Olaf Alders <olaf@wundersolutions.com>
- Pedro Melo <melo@simplicidade.org>
View
3  bin/tidyall
@@ -236,7 +236,8 @@ distribution comes with plugins for:
=item *
Perl: L<perlcritic|Code::TidyAll::Plugin::PerlCritic>,
-L<perltidy|Code::TidyAll::Plugin::PerlTidy>
+L<perltidy|Code::TidyAll::Plugin::PerlTidy>,
+L<perltidy-sweet|Code::TidyAll::Plugin::PerlTidy::Sweetened>
=item *
View
1  cpanfile
@@ -59,6 +59,7 @@ on 'develop' => sub {
requires "Mason::Tidy" => "0";
requires "Mason::Tidy::App" => "0";
requires "Perl::Tidy" => "0";
+ requires "Perl::Tidy::Sweetened" => "0";
requires "Pod::Checker" => "0";
requires "Pod::Spell" => "0";
requires "Pod::Tidy" => "0";
View
2  dist.ini
@@ -13,6 +13,7 @@ prereqs_skip = JSON
prereqs_skip = Mason::Tidy
prereqs_skip = Mason::Tidy::App
prereqs_skip = Perl::Tidy
+prereqs_skip = Perl::Tidy::Sweetened
prereqs_skip = Pod::Checker
prereqs_skip = Pod::Spell
prereqs_skip = Pod::Tidy
@@ -36,6 +37,7 @@ JSON = 0
Mason::Tidy = 0
Mason::Tidy::App = 0
Perl::Tidy = 0
+Perl::Tidy::Sweetened = 0
Pod::Checker = 0
Pod::Spell = 0
Pod::Tidy = 0
View
81 lib/Code/TidyAll/Plugin/PerlTidySweet.pm
@@ -0,0 +1,81 @@
+package Code::TidyAll::Plugin::PerlTidySweet;
@autarch Owner
autarch added a note

You need to add a blank line after the package statement for the benefit of dzil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+use Capture::Tiny qw(capture_merged);
+use Perl::Tidy::Sweetened;
+use Moo;
+extends 'Code::TidyAll::Plugin';
+
+sub transform_source {
+ my ( $self, $source ) = @_;
+
+ # perltidy reports errors in two different ways.
+ # Argument/profile errors are output and an error_flag is returned.
+ # Syntax errors are sent to errorfile or stderr, depending on the
+ # the setting of -se/-nse (aka --standard-error-output). These flags
+ # might be hidden in other bundles, e.g. -pbp. Be defensive and
+ # check both.
+ my ( $output, $error_flag, $errorfile, $stderr, $destination );
+ $output = capture_merged {
+ $error_flag = Perl::Tidy::Sweetened::perltidy(
+ argv => $self->argv,
+ source => \$source,
+ destination => \$destination,
+ stderr => \$stderr,
+ errorfile => \$errorfile
+ );
+ };
+ die $stderr if $stderr;
+ die $errorfile if $errorfile;
+ die $output if $error_flag;
+ print STDERR $output if defined($output);
+ return $destination;
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Code::TidyAll::Plugin::PerlTidySweet - use perltidy-sweet with tidyall
+
+=head1 SYNOPSIS
+
+ # In configuration:
+
+ ; Configure in-line
+ ;
+ [PerlTidySweet]
+ select = lib/**/*.pm
+ argv = --noll
+
+ ; or refer to a .perltidyrc in the same directory
+ ;
+ [PerlTidySweet]
+ select = lib/**/*.pm
+ argv = --profile=$ROOT/.perltidyrc
+
+=head1 DESCRIPTION
+
+Runs L<perltidy-sweet>, a Perl tidier based on Perl::Tidy that also
+supports new syntactic sugar as provided by L<Method::Signature::Simple>,
+L<MooseX::Method::Signatures> and the p5-mop.
+
+=head1 INSTALLATION
+
+Install perltidy-sweet from CPAN.
+
+ cpanm Perl::Tidy::Sweet
+
+=head1 CONFIGURATION
+
+=over
+
+=item argv
+
+Arguments to pass to perltidy-sweet
+
+=back
+
View
38 t/lib/Test/Code/TidyAll/Plugin/PerlTidySweet.pm
@@ -0,0 +1,38 @@
+package Test::Code::TidyAll::Plugin::PerlTidySweet;
+
+use Test::Class::Most parent => 'Test::Code::TidyAll::Plugin';
+
+sub test_main : Tests {
+ my $self = shift;
+
+ my $source = 'if ( $foo) {\nmy $bar = $baz;\n}\n';
+ $self->tidyall(
+ source => $source,
+ expect_tidy => 'if ($foo) {\n my $bar = $baz;\n}\n'
+ );
+ $self->tidyall(
+ conf => { argv => '-bl' },
+ source => $source,
+ expect_tidy => 'if ($foo)\n{\n my $bar = $baz;\n}\n'
+ );
+ $self->tidyall(
+ source => 'if ($foo) {\n my $bar = $baz;\n}\n',
+ expect_ok => 1
+ );
+ $self->tidyall(
+ source => 'method foo ($x,$y){\nmy $x=$self->x;}\n',
+ expect_tidy => 'method foo ($x,$y) {\n my $x = $self->x;\n}\n',
+ );
+ $self->tidyall(
+ source => 'if ($foo) {\n my $bar = $baz;\n',
+ expect_error => qr/Final nesting depth/
+ );
+ $self->tidyall(
+ conf => { argv => '--badoption' },
+ source => $source,
+ expect_error => qr/Unknown option: badoption/
+ );
+}
+
+1;
+1;
View
6 tidyall.ini
@@ -2,6 +2,10 @@
argv = -noll -l=100
select = {bin,lib,t}/**/{tidyall,*.{pl,pm,t}}
+[PerlTidySweet]
+argv = -noll -l=100
+select = {bin,lib,t}/**/{tidyall,*.{pl,pm,t}}
+
[PodTidy]
select = {bin,lib}/**/{tidyall,*.{pl,pm,pod}}
@@ -22,4 +26,4 @@ select = .gitignore .ispell* **/.gitignore
select = {bin,lib,t}/**/*.{pl,pm,t}
[Perl::AlignMooseAttributes]
-select = {bin,lib,t}/**/*.{pl,pm,t}
+select = {bin,lib,t}/**/*.{pl,pm,t}
View
4 xt/author/Plugin-PerlTidySweet.t
@@ -0,0 +1,4 @@
+#!/usr/bin/perl
+use lib 't/lib';
+use Test::Code::TidyAll::Plugin::PerlTidySweet;
+Test::Code::TidyAll::Plugin::PerlTidySweet->runtests;
Something went wrong with that request. Please try again.