Created
January 20, 2012 17:43
-
-
Save nicwolff/1648639 to your computer and use it in GitHub Desktop.
IO::File::Sitemap
This file contains hidden or 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}; | |
| } | |
| package IO::File::Sitemap; | |
| use base 'IO::File::Cycle'; | |
| sub close { | |
| my $io = shift; | |
| my $old_filename = $io->filename; | |
| $io->SUPER::close; | |
| system "gzip -f $old_filename"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment