AnnoCPAN::Archive - Simple archive abstraction layer


AnnoCPAN documentation Contained in the AnnoCPAN distribution.

Index


Code Index:

NAME

Top

AnnoCPAN::Archive - Simple archive abstraction layer

SYNOPSIS

Top

DESCRIPTION

Top

AnnoCPAN is expected to handle both tar.gz and zip archives. Archive::Tar and Archive::Zip take care of accessing those types of files, but they have different interfaces. AnnoCPAN::Archive provides a common interface to the very few methods that are actually needed.

METHODS

Top

$class->new($fname)

Create a new AnnoCPAN::Archive object. It uses the filename extension, which must be .zip or .tar.gz, to determine the type of archive. Returns undefined if there is any problem.

$obj->files

Returns a list of the filenames contained in the archive.

$obj->read_file($fname)

Returns as a string the contents of file $fname in the archive.

SEE ALSO

Top

Archive::Tar, Archive::Zip

There are other modules on CPAN, such as Archive::Any, Archive::Extract, and File::Archive, that seem to do similar things, but they didn't appear to do exactly what I wanted or seemed too complicated, so I resorted to rolling my own. It was just a dozen lines of code (heck, this documentation is way longer than the code itself!)

AUTHOR

Top

Ivan Tubert-Brohman <itub@cpan.org>

COPYRIGHT

Top


AnnoCPAN documentation Contained in the AnnoCPAN distribution.
package AnnoCPAN::Archive;

$VERSION = '0.22';

use strict;
use warnings;

use Archive::Zip;
use Archive::Tar;

sub new {
    my ($class, $fname) = @_;
    return AnnoCPAN::Archive::Zip->new($fname) 
        if $fname =~ /\.zip$/;
    return AnnoCPAN::Archive::Tar->new($fname) 
        if $fname =~ /(\.tar\.gz|\.tgz)$/;
    return;
}

package AnnoCPAN::Archive::Zip;
our @ISA = qw(AnnoCPAN::Archive Archive::Zip::Archive);
sub new { shift->Archive::Zip::Archive::new(@_) }
sub files { shift->memberNames }
sub read_file { shift->contents(@_) }

package AnnoCPAN::Archive::Tar;
our @ISA = qw(AnnoCPAN::Archive Archive::Tar);
sub new { shift->Archive::Tar::new(@_) }
sub files { shift->list_files }
sub read_file { shift->get_content(@_) }

1;