Alien-ROOT
view release on metacpan or search on metacpan
inc/inc_Archive-Extract/Archive/Extract.pm view on Meta::CPAN
Bzip2 compressed file, as produced by, for example, C</bin/bzip2>.
Corresponds to a C<.bz2> suffix.
=item tbz
Bzip2 compressed tar file, as produced by, for example C</bin/tar -j>.
Corresponds to a C<.tbz> or C<.tar.bz2> suffix.
=item lzma
Lzma compressed file, as produced by C</bin/lzma>.
Corresponds to a C<.lzma> suffix.
=item xz
Xz compressed file, as produced by C</bin/xz>.
Corresponds to a C<.xz> suffix.
=item txz
Xz compressed tar file, as produced by, for example C</bin/tar -J>.
Corresponds to a C<.txz> or C<.tar.xz> suffix.
=back
Returns a C<Archive::Extract> object on success, or false on failure.
=cut
### constructor ###
sub new {
my $class = shift;
my %hash = @_;
### see above why we use subs here and generate the template;
### it's basically to not re-use arrayrefs
my %utmpl = map { $_ => $tmpl->{$_}->() } keys %$tmpl;
my $parsed = check( \%utmpl, \%hash ) or return;
### make sure we have an absolute path ###
my $ar = $parsed->{archive} = File::Spec->rel2abs( $parsed->{archive} );
### figure out the type, if it wasn't already specified ###
unless ( $parsed->{type} ) {
$parsed->{type} =
$ar =~ /.+?\.(?:tar\.gz|tgz)$/i ? TGZ :
$ar =~ /.+?\.gz$/i ? GZ :
$ar =~ /.+?\.tar$/i ? TAR :
$ar =~ /.+?\.(zip|jar|ear|war|par)$/i ? ZIP :
$ar =~ /.+?\.(?:tbz2?|tar\.bz2?)$/i ? TBZ :
$ar =~ /.+?\.bz2$/i ? BZ2 :
$ar =~ /.+?\.Z$/ ? Z :
$ar =~ /.+?\.lzma$/ ? LZMA :
$ar =~ /.+?\.(?:txz|tar\.xz)$/i ? TXZ :
$ar =~ /.+?\.xz$/ ? XZ :
'';
}
bless $parsed, $class;
### don't know what type of file it is
### XXX this *has* to be an object call, not a package call
return $parsed->_error(loc("Cannot determine file type for '%1'",
$parsed->{archive} )) unless $parsed->{type};
return $parsed;
}
}
=head2 $ae->extract( [to => '/output/path'] )
Extracts the archive represented by the C<Archive::Extract> object to
the path of your choice as specified by the C<to> argument. Defaults to
C<cwd()>.
Since C<.gz> files never hold a directory, but only a single file; if
the C<to> argument is an existing directory, the file is extracted
there, with its C<.gz> suffix stripped.
If the C<to> argument is not an existing directory, the C<to> argument
is understood to be a filename, if the archive type is C<gz>.
In the case that you did not specify a C<to> argument, the output
file will be the name of the archive file, stripped from its C<.gz>
suffix, in the current working directory.
C<extract> will try a pure perl solution first, and then fall back to
commandline tools if they are available. See the C<GLOBAL VARIABLES>
section below on how to alter this behaviour.
It will return true on success, and false on failure.
On success, it will also set the follow attributes in the object:
=over 4
=item $ae->extract_path
This is the directory that the files where extracted to.
=item $ae->files
This is an array ref with the paths of all the files in the archive,
relative to the C<to> argument you specified.
To get the full path to an extracted file, you would use:
File::Spec->catfile( $to, $ae->files->[0] );
Note that all files from a tar archive will be in unix format, as per
the tar specification.
=back
=cut
sub extract {
my $self = shift;
my %hash = @_;
### reset error messages
$self->_error_msg( [] );
$self->_error_msg_long( [] );
( run in 0.468 second using v1.01-cache-2.11-cpan-5735350b133 )