| AnnoCPAN documentation | Contained in the AnnoCPAN distribution. |
AnnoCPAN::Archive - Simple archive abstraction layer
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.
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.
Returns a list of the filenames contained in the archive.
Returns as a string the contents of file $fname in the archive.
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!)
Ivan Tubert-Brohman <itub@cpan.org>
Copyright (c) 2005 Ivan Tubert-Brohman. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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;