Skip to content
Browse files

Refactored for handling arrays, tests updated to not invoke stricture…

…s extended tests.
  • Loading branch information...
1 parent a900d88 commit 846cb382382befe7a3b6bf5db5b6621ddda8489d @shadowcat-mst shadowcat-mst committed with
Showing with 52 additions and 21 deletions.
  1. +21 −21 lib/File/Set/Writer.pm
  2. +2 −0 t/00_load.t
  3. +17 −0 t/00_load.t.rej
  4. +2 −0 t/01_default.t
  5. +2 −0 t/02_dies_ok.t
  6. +2 −0 t/03_print.t
  7. +2 −0 t/04_limit_files.t
  8. +2 −0 t/04_limit_handles.t
  9. +2 −0 t/04_limit_lines.t
View
42 lib/File/Set/Writer.pm
@@ -23,11 +23,15 @@ has expire_handles_batch_size => ( is => 'rw', isa => PositiveInt );
# to manage the values.
around expire_files_batch_size => sub {
- $_[0]->(@_[1..$#_]) || int $_[1]->max_files/5
+ my ( $orig, $self ) = ( shift, shift );
+
+ return $self->$orig( @_ ) || int( $self->max_files / 5 );
};
around expire_handles_batch_size => sub {
- $_[0]->(@_[1..$#_]) || int $_[1]->max_handles/5
+ my ( $orig, $self ) = ( shift, shift );
+
+ return $self->$orig( @_ ) || int( $self->max_handles / 5 );
};
sub print {
@@ -35,7 +39,7 @@ sub print {
push @{$self->{queue}->{$file}}, @lines;
- $self->_write_file( $file )
+ $self->_write_files( $file )
if @{$self->{queue}->{$file}} >= $self->max_lines;
$self->_write_pending_files
@@ -55,26 +59,26 @@ sub _write_pending_files {
scalar @{$self->{queue}->{$b} || []} <=> scalar @{$self->{queue}->{$a} || []}
} keys %{$self->{queue}};
- foreach my $i ( 0 .. $self->expire_files_batch_size ) {
- $self->_write_file( $files[$i] ) if $files[$i];
- }
+ $self->_write_files( splice @files, 0, $self->expire_files_batch_size );
}
-# Given the name of a file with queued lines, write the lines to the
+# Given names of files with queued lines, write the lines to the
# file handle with $self->_write(), joining the lines together with
# $self->line_join.
-sub _write_file {
- my ( $self, $file ) = @_;
+sub _write_files {
+ my ( $self, @files ) = @_;
- die "Error _write_file called with invalid argument \"$file\""
- unless defined $file and exists $self->{queue}->{$file};
+ foreach my $file ( @files ) {
+ die "Error _write_files called with invalid argument \"$file\""
+ unless defined $file and exists $self->{queue}->{$file};
- $self->_write(
- $file,
- join( $self->line_join, @{$self->{queue}->{$file}} ) . $self->line_join
- );
- delete $self->{queue}->{$file};
+ $self->_write(
+ $file,
+ join( $self->line_join, @{$self->{queue}->{$file}}, '' )
+ );
+ delete $self->{queue}->{$file};
+ }
}
@@ -123,12 +127,8 @@ sub _write {
sub _sync {
my ( $self ) = @_;
-
- foreach my $file ( keys %{$self->{queue}} ) {
- $self->_write_file( $file );
- }
- return $self;
+ $self->_write_files( keys %{$self->{queue}} );
}
# Return the count of open file handles currently in the cache.
View
2 t/00_load.t
@@ -1,6 +1,8 @@
#!/usr/bin/perl
use warnings;
use strict;
+# Disable extra testing for deficient development environments
+BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0; }
use Test::More;
use_ok( "File::Set::Writer" );
View
17 t/00_load.t.rej
@@ -0,0 +1,17 @@
+***************
+*** 1,6 ****
+ #!/usr/bin/perl
+ use warnings;
+ use strict;
+ use Test::More;
+
+ use_ok( "File::Set::Writer" );
+--- 1,8 ----
+ #!/usr/bin/perl
+ use warnings;
+ use strict;
++ # Disable extra testing for deficient development environments
++ BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0; }
+ use Test::More;
+
+ use_ok( "File::Set::Writer" );
View
2 t/01_default.t
@@ -1,6 +1,8 @@
#!/usr/bin/perl
use warnings;
use strict;
+# Disable extra testing for deficient development environments
+BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0; }
use File::Set::Writer;
use Test::More;
View
2 t/02_dies_ok.t
@@ -1,6 +1,8 @@
#!/usr/bin/perl
use warnings;
use strict;
+# Disable extra testing for deficient development environments
+BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0; }
use Test::More;
use File::Set::Writer;
View
2 t/03_print.t
@@ -1,6 +1,8 @@
#!/usr/bin/perl
use warnings;
use strict;
+# Disable extra testing for deficient development environments
+BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0; }
use Test::More;
use File::Set::Writer;
View
2 t/04_limit_files.t
@@ -1,6 +1,8 @@
#!/usr/bin/perl
use warnings;
use strict;
+# Disable extra testing for deficient development environments
+BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0; }
use Test::More;
use File::Set::Writer;
View
2 t/04_limit_handles.t
@@ -1,6 +1,8 @@
#!/usr/bin/perl
use warnings;
use strict;
+# Disable extra testing for deficient development environments
+BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0; }
use Test::More;
use File::Set::Writer;
View
2 t/04_limit_lines.t
@@ -1,6 +1,8 @@
#!/usr/bin/perl
use warnings;
use strict;
+# Disable extra testing for deficient development environments
+BEGIN { $ENV{PERL_STRICTURES_EXTRA} = 0; }
use Test::More;
use File::Set::Writer;

0 comments on commit 846cb38

Please sign in to comment.
Something went wrong with that request. Please try again.