[libcode-tidyall-perl] 21/374: add result object
Jonas Smedegaard
js at alioth.debian.org
Sun Sep 29 22:25:41 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 1fe0aa452e8b399bf0737ddd8878236aa6de9b94
Author: Jonathan Swartz <swartz at pobox.com>
Date: Fri Jun 15 19:25:24 2012 -0500
add result object
---
lib/Code/TidyAll.pm | 11 +++++++++--
lib/Code/TidyAll/Result.pm | 25 +++++++++++++++++++++++++
lib/Code/TidyAll/t/Basic.pm | 7 ++++++-
3 files changed, 40 insertions(+), 3 deletions(-)
diff --git a/lib/Code/TidyAll.pm b/lib/Code/TidyAll.pm
index 17872c1..6f8db9a 100644
--- a/lib/Code/TidyAll.pm
+++ b/lib/Code/TidyAll.pm
@@ -4,6 +4,7 @@ use Config::INI::Reader;
use Code::TidyAll::Cache;
use Code::TidyAll::Util
qw(abs2rel basename can_load dirname dump_one_line mkpath read_dir read_file uniq write_file);
+use Code::TidyAll::Result;
use Date::Format;
use Digest::SHA1 qw(sha1_hex);
use File::Find qw(find);
@@ -121,14 +122,17 @@ sub load_plugin {
sub process_all {
my $self = shift;
- $self->process_files( keys( %{ $self->matched_files } ) );
+ return $self->process_files( keys( %{ $self->matched_files } ) );
}
sub process_files {
my ( $self, @files ) = @_;
+
+ my $error_count = 0;
foreach my $file (@files) {
- $self->_process_file($file);
+ $error_count++ if $self->_process_file($file);
}
+ return Code::TidyAll::Result->new( error_count => $error_count );
}
sub _process_file {
@@ -138,6 +142,7 @@ sub _process_file {
my $small_path = $self->_small_path($file);
if ( !@plugins ) {
$self->msg( "[no plugins apply] %s", $small_path );
+ return;
}
my $cache = $self->cache;
@@ -167,9 +172,11 @@ sub _process_file {
if ($error) {
$self->msg( "%s", $error );
+ return 1;
}
else {
$cache->set( "sig/$small_path", $self->_file_sig( $file, $new_contents ) ) if $cache;
+ return;
}
}
diff --git a/lib/Code/TidyAll/Result.pm b/lib/Code/TidyAll/Result.pm
new file mode 100644
index 0000000..bb460d6
--- /dev/null
+++ b/lib/Code/TidyAll/Result.pm
@@ -0,0 +1,25 @@
+package Code::TidyAll::Result;
+use strict;
+use warnings;
+
+use Object::Tiny qw(error_count);
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Code::TidyAll::Result - Result returned from Code::TidyAll methods
+
+=head1 METHODS
+
+=over
+
+=item error_count
+
+The number of errors that occurred.
+
+=back
diff --git a/lib/Code/TidyAll/t/Basic.pm b/lib/Code/TidyAll/t/Basic.pm
index 0e27307..32f4b94 100644
--- a/lib/Code/TidyAll/t/Basic.pm
+++ b/lib/Code/TidyAll/t/Basic.pm
@@ -38,9 +38,14 @@ sub tidy {
%$options
);
- my $output = capture_stdout { $ct->process_all() };
+ my $result;
+ my $output = capture_stdout { $result = $ct->process_all() };
if ( $params{errors} ) {
like( $output, $params{errors}, "$desc - errors" );
+ ok( $result->error_count > 0, "$desc - error_count > 0" );
+ }
+ else {
+ is( $result->error_count, 0, "$desc - error_count == 0" );
}
while ( my ( $path, $content ) = each( %{ $params{dest} } ) ) {
is( read_file("$root_dir/$path"), $content, "$desc - $path content" );
--
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