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