App::Hachero::Plugin::Fetch::Gunzip - gunzips '*.gz' files in work_path


App-Hachero documentation Contained in the App-Hachero distribution.

Index


Code Index:

NAME

Top

App::Hachero::Plugin::Fetch::Gunzip - gunzips '*.gz' files in work_path

SYNOPSIS

Top

  ---
  global:
    work_path: /path/to/your/work_path
  plugins:
    - module: Fetch::Gunzip

DESCRIPTION

Top

Gunzips '*.gz' files in work_path.

implemented hooks

* fetch

AUTHOR

Top

Nobuo Danjou <nobuo.danjou@gmail.com>

SEE ALSO

Top

App::Hachero

Net::Amazon::S3


App-Hachero documentation Contained in the App-Hachero distribution.

package App::Hachero::Plugin::Fetch::Gunzip;
use strict;
use warnings;
use base qw(App::Hachero::Plugin::Base);
use IO::Uncompress::Gunzip qw(gunzip $GunzipError);
use File::Basename;
use File::Spec::Functions;
use File::Find::Rule;

sub fetch : Hook {
    my ($self, $context, $args) = @_;
    my $config = $self->config->{config};
    my $work_path = $context->conf->{global}->{work_path};

    my @files = File::Find::Rule->file()
                               ->name('*.gz')
                               ->in($work_path);
    
    for my $file (@files) {
        my $dest = catfile($work_path, basename($file, '.gz'));
        if (gunzip $file => $dest) {
            unlink $file;
        } else {
            $context->log(error => "extraction of $file failed: $GunzipError");
            next;
        }
    }
}

1;
__END__