Skip to content

Instantly share code, notes, and snippets.

@nicwolff
Created January 20, 2012 17:43
Show Gist options
  • Save nicwolff/1648637 to your computer and use it in GitHub Desktop.
Save nicwolff/1648637 to your computer and use it in GitHub Desktop.
IO::File::Cycle
package IO::File::Cycle;
use base 'IO::File';
sub open {
my $io = shift;
*{$io} = \ {
cycle_count => 1,
cycle_file => $_[0],
cycle_called_with => [@_],
};
$io->SUPER::open(@_);
}
sub cycle {
my $io = shift;
$io->close;
my ($base_filename, @mode_and_perms) = @{$$$io->{cycle_called_with}};
$$$io->{cycle_file} = join '.', $base_filename, ++$$$io->{cycle_count};
$io->SUPER::open($$$io->{cycle_file}, @mode_and_perms);
}
sub filename {
my $io = shift;
return $$$io->{cycle_file};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment