Created
January 20, 2012 17:43
-
-
Save nicwolff/1648637 to your computer and use it in GitHub Desktop.
IO::File::Cycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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