| 1 | package ETLp::Plugin::Iterative::Gzip; | ||
| 2 | |||
| 3 | use MooseX::Declare; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | ETLp::Plugin::Iterative::Gzip - Plugin to gzip files | ||
| 8 | |||
| 9 | =cut | ||
| 10 | |||
| 11 | class ETLp::Plugin::Iterative::Gzip extends ETLp::Plugin { | ||
| 12 | use IO::Compress::Gzip qw($GzipError); | ||
| 13 | |||
| 14 | =head1 METHODS | ||
| 15 | |||
| 16 | =head2 type | ||
| 17 | |||
| 18 | Registers the plugin type. | ||
| 19 | |||
| 20 | =cut | ||
| 21 | |||
| 22 | sub type { | ||
| 23 | return 'gzip'; | ||
| 24 | } | ||
| 25 | |||
| 26 | =head2 run | ||
| 27 | |||
| 28 | Gzips the supplied filename. Will not proceed if the name ends in .gz | ||
| 29 | |||
| 30 | =head3 paramaters | ||
| 31 | |||
| 32 | * filename - the name of the file to be gzipped | ||
| 33 | |||
| 34 | -head3 returns | ||
| 35 | |||
| 36 | * new filename - the name for the file following | ||
| 37 | |||
| 38 | =cut | ||
| 39 | |||
| 40 | method run (Str $filename) { | ||
| 41 | my $file_process = $self->audit->item->file_process; | ||
| 42 | |||
| 43 | # Don't continue if the file is already gzipped | ||
| 44 | if ($filename =~ /\.gz$/) { | ||
| 45 | $file_process->update_message("file already gzipped"); | ||
| 46 | return $filename; | ||
| 47 | } | ||
| 48 | |||
| 49 | my $output = $filename . '.gz'; | ||
| 50 | |||
| 51 | unless (IO::Compress::Gzip::gzip $filename => $output) { | ||
| 52 | unlink $output; | ||
| 53 | ETLpException->throw(error => $GzipError); | ||
| 54 | }; | ||
| 55 | |||
| 56 | unlink $filename; | ||
| 57 | $file_process->update_message("file gzipped"); | ||
| 58 | return $output; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | =head1 LICENSE AND COPYRIGHT | ||
| 63 | |||
| 64 | Copyright 2010 Redbone Systems Ltd | ||
| 65 | |||
| 66 | This program is free software; you can redistribute it and/or modify it | ||
| 67 | under the terms of either: the GNU General Public License as published | ||
| 68 | by the Free Software Foundation; or the Artistic License. | ||
| 69 | |||
| 70 | The terms are in the LICENSE file that accompanies this application |