ext/Archive-Tar/t/03_file.t Archive::Tar tests
ext/Archive-Tar/t/04_resolved_issues.t Archive::Tar tests
ext/Archive-Tar/t/05_iter.t Archive::Tar tests
+ext/Archive-Tar/t/06_error.t Archive::Tar tests
ext/Archive-Tar/t/90_symlink.t Archive::Tar tests
ext/Archive-Tar/t/99_pod.t Archive::Tar tests
ext/Archive-Tar/t/src/header/signed.tar Archive::Tar tests
$DEBUG = 0;
$WARN = 1;
$FOLLOW_SYMLINK = 0;
-$VERSION = "1.52";
+$VERSION = "1.54";
$CHOWN = 1;
$CHMOD = 1;
$SAME_PERMISSIONS = $> == 0 ? 1 : 0;
### copying $tmpl here since a shallow copy makes it use the
### same aref, causing for files to remain in memory always.
- my $obj = bless { _data => [ ], _file => 'Unknown' }, $class;
+ my $obj = bless { _data => [ ], _file => 'Unknown', _error => '' }, $class;
if (@_) {
unless ( $obj->read( @_ ) ) {
my $self = shift;
my $msg = $error = shift;
$longmess = Carp::longmess($error);
+ if (ref $self) {
+ $self->{_error} = $error;
+ $self->{_longmess} = $longmess;
+ }
### set Archive::Tar::WARN to 0 to disable printing
### of errors
sub error {
my $self = shift;
- return shift() ? $longmess : $error;
+ if (ref $self) {
+ return shift() ? $self->{_longmess} : $self->{_error};
+ } else {
+ return shift() ? $longmess : $error;
+ }
}
}
it all in memory. Each time the function is called it will return the
next file in the tarball. The files are returned as
C<Archive::Tar::File> objects. The iterator function returns the
-empty list once it has exhausted the the files contained.
+empty list once it has exhausted the files contained.
The second argument can be a hash reference with options, which are
identical to the arguments passed to C<read()>.
return unless $handle; # handle exhausted?
### read data, should only return file
- @data = @{ $class->_read_tar($handle, { %$opts, limit => 1 }) };
+ my $tarfile = $class->_read_tar($handle, { %$opts, limit => 1 });
+ @data = @$tarfile if ref $tarfile && ref $tarfile eq 'ARRAY';
### return one piece of data
return shift(@data) if @data;
warn $tar->error unless $tar->extract;
+Note that in older versions of this module, the C<error()> method
+would return an effectively global value even when called an instance
+method as above. This has since been fixed, and multiple instances of
+C<Archive::Tar> now have separate error strings.
+
=head2 $Archive::Tar::INSECURE_EXTRACT_MODE
This variable indicates whether C<Archive::Tar> should allow
--- /dev/null
+BEGIN {
+ if( $ENV{PERL_CORE} ) {
+ chdir '../lib/Archive/Tar' if -d '../lib/Archive/Tar';
+ }
+ use lib '../../..';
+}
+
+BEGIN { chdir 't' if -d 't' }
+
+use Test::More 'no_plan';
+use strict;
+use lib '../lib';
+
+use Archive::Tar;
+use File::Spec;
+
+$Archive::Tar::WARN = 0;
+
+my $t1 = Archive::Tar->new;
+my $t2 = Archive::Tar->new;
+
+is($Archive::Tar::error, "", "global error string is empty");
+is($t1->error, "", "error string of object 1 is empty");
+is($t2->error, "", "error string of object 2 is empty");
+
+ok(!$t1->read(), "can't read without a file");
+
+isnt($t1->error, "", "error string of object 1 is set");
+is($Archive::Tar::error, $t1->error, "global error string equals that of object 1");
+is($Archive::Tar::error, Archive::Tar->error, "the class error method returns the global error");
+is($t2->error, "", "error string of object 2 is still empty");
+
+my $src = File::Spec->catfile( qw[src short b] );
+ok(!$t2->read($src), "error when opening $src");
+
+isnt($t2->error, "", "error string of object 1 is set");
+isnt($t2->error, $t1->error, "error strings of objects 1 and 2 differ");
+is($Archive::Tar::error, $t2->error, "global error string equals that of object 2");
+is($Archive::Tar::error, Archive::Tar->error, "the class error method returns the global error");