Archive::Peek - Peek into archives without extracting them


Archive-Peek documentation Contained in the Archive-Peek distribution.

Index


Code Index:

NAME

Top

Archive::Peek - Peek into archives without extracting them

SYNOPSIS

Top

  use Archive::Peek;
  my $peek = Archive::Peek->new( filename => 'archive.tgz' );
  my @files = $peek->files();
  my $contents = $peek->file('README.txt')

DESCRIPTION

Top

This module lets you peek into archives without extracting them. It currently supports tar files and zip files.

METHODS

Top

new

The constructor takes the filename of the archive to peek into:

  my $peek = Archive::Peek->new( filename => 'archive.tgz' );

files

Returns the files in the archive:

  my @files = $peek->files();

file

Returns the contents of a file in the archive:

  my $contents = $peek->file('README.txt')

AUTHOR

Top

Leon Brocard <acme@astray.com>

COPYRIGHT

Top

LICENSE

Top

This module is free software; you can redistribute it or modify it under the same terms as Perl itself.


Archive-Peek documentation Contained in the Archive-Peek distribution.

package Archive::Peek;
use Moose;
use Archive::Peek::Tar;
use Archive::Peek::Zip;
use MooseX::Types::Path::Class qw( File );
our $VERSION = '0.34';

has 'filename' => (
    is       => 'ro',
    isa      => File,
    required => 1,
    coerce   => 1,
);

sub BUILD {
    my $self     = shift;
    my $filename = $self->filename;
    my $basename = $filename->basename;
    if ( $basename =~ /\.zip$/i ) {
        bless $self, 'Archive::Peek::Zip';
    } elsif ( $basename =~ /(\.tar|\.tar\.gz|\.tgz)$/i ) {
        bless $self, 'Archive::Peek::Tar';
    } else {
        confess("Failed to open $filename");
    }
}

1;

__END__