[libcode-tidyall-perl] 240/374: handle errors correctly in MasonTidy; use internal MasonTidy API

Jonas Smedegaard js at alioth.debian.org
Sun Sep 29 22:26:27 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 95d8a067a4524e7d5389efd786436c55a9966325
Author: Jonathan Swartz <swartz at pobox.com>
Date:   Fri Sep 14 13:07:35 2012 -0400

    handle errors correctly in MasonTidy; use internal MasonTidy API
---
 lib/Code/TidyAll/Plugin/MasonTidy.pm   |   19 ++++++++++++++-----
 lib/Code/TidyAll/t/Plugin/MasonTidy.pm |    9 +++++++--
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/lib/Code/TidyAll/Plugin/MasonTidy.pm b/lib/Code/TidyAll/Plugin/MasonTidy.pm
index aefd950..3e5cca7 100644
--- a/lib/Code/TidyAll/Plugin/MasonTidy.pm
+++ b/lib/Code/TidyAll/Plugin/MasonTidy.pm
@@ -1,14 +1,23 @@
 package Code::TidyAll::Plugin::MasonTidy;
-use IPC::System::Simple qw(run);
+use Capture::Tiny qw(capture_merged);
+use Mason::Tidy;
 use Moo;
+use Text::ParseWords qw(shellwords);
 extends 'Code::TidyAll::Plugin';
 
 sub _build_cmd { 'masontidy' }
 
-sub transform_file {
-    my ( $self, $file ) = @_;
-
-    run( sprintf( "%s --replace %s %s", $self->cmd, $self->argv, $file ) );
+sub transform_source {
+    my ( $self, $source ) = @_;
+
+    my %params;
+    my $argv_list = [ shellwords( $self->argv ) ];
+    my $opts_good;
+    my $output = capture_merged { $opts_good = Mason::Tidy->get_options( $argv_list, \%params ) };
+    die $output if !$opts_good;
+    my $mt   = Mason::Tidy->new(%params);
+    my $dest = $mt->tidy($source);
+    return $dest;
 }
 
 1;
diff --git a/lib/Code/TidyAll/t/Plugin/MasonTidy.pm b/lib/Code/TidyAll/t/Plugin/MasonTidy.pm
index 53533fc..f04dd58 100644
--- a/lib/Code/TidyAll/t/Plugin/MasonTidy.pm
+++ b/lib/Code/TidyAll/t/Plugin/MasonTidy.pm
@@ -13,14 +13,19 @@ sub test_main : Tests {
     );
     $self->tidyall(
         source      => $source,
-        conf        => { argv => '--perltidy-argv="-pt=2"' },
-        expect_tidy => '% if ($foo) {\n%   bar(1, 2);\n% }'
+        conf        => { argv => '--perltidy-argv="-pt=2 -i=3"' },
+        expect_tidy => '% if ($foo) {\n%    bar(1, 2);\n% }'
     );
     $self->tidyall(
         source      => $source,
         conf        => { argv => '--perltidy-line-argv=" "' },
         expect_tidy => '% if ($foo) {\n%     bar( 1, 2 );\n% }'
     );
+    $self->tidyall(
+        source       => $source,
+        conf         => { argv => '--badoption' },
+        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