[libcode-tidyall-perl] 234/374: handle perltidy option errors

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:26 UTC 2013


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository libcode-tidyall-perl.

commit 3930648ba5f1da47c3ef479ffba09486c979d716
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Fri Sep 14 11:21:46 2012 -0400

    handle perltidy option errors
---
 lib/Code/TidyAll/Plugin/PerlTidy.pm   |   26 +++++++++++++++++---------
 lib/Code/TidyAll/t/Plugin/PerlTidy.pm |    5 +++++
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/lib/Code/TidyAll/Plugin/PerlTidy.pm b/lib/Code/TidyAll/Plugin/PerlTidy.pm
index 9334c2c..79b6a3e 100644
--- a/lib/Code/TidyAll/Plugin/PerlTidy.pm
+++ b/lib/Code/TidyAll/Plugin/PerlTidy.pm
@@ -1,4 +1,5 @@
 package Code::TidyAll::Plugin::PerlTidy;
+use Capture::Tiny qw(capture_merged);
 use Perl::Tidy;
 use Moo;
 extends 'Code::TidyAll::Plugin';
@@ -6,15 +7,22 @@ extends 'Code::TidyAll::Plugin';
 sub transform_source {
     my ( $self, $source ) = @_;
 
-    my $errorfile;
-    no strict 'refs';
-    Perl::Tidy::perltidy(
-        argv        => $self->argv,
-        source      => \$source,
-        destination => \my $destination,
-        errorfile   => \$errorfile
-    );
-    die $errorfile if $errorfile;
+    # perltidy reports errors in two different ways.
+    # Argument/profile errors are output and an error_flag is returned.
+    # Syntax errors are sent to errorfile.
+    #
+    my ( $output, $error_flag, $errorfile, $destination );
+    $output = capture_merged {
+        $error_flag = Perl::Tidy::perltidy(
+            argv        => $self->argv,
+            source      => \$source,
+            destination => \$destination,
+            errorfile   => \$errorfile
+        );
+    };
+    die $errorfile       if $errorfile;
+    die $output          if $error_flag;
+    print STDERR $output if defined($output);
     return $destination;
 }
 
diff --git a/lib/Code/TidyAll/t/Plugin/PerlTidy.pm b/lib/Code/TidyAll/t/Plugin/PerlTidy.pm
index 5a7b663..16761a6 100644
--- a/lib/Code/TidyAll/t/Plugin/PerlTidy.pm
+++ b/lib/Code/TidyAll/t/Plugin/PerlTidy.pm
@@ -22,6 +22,11 @@ sub test_main : Tests {
         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;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcode-tidyall-perl.git



More information about the Pkg-perl-cvs-commits mailing list