What I needed to do was to catch broken tar files where some files did not extract. The default behaviour is to output a warning to stdout and proceed with the next file as if nothing had happened.
$Archive::Tar::WARN
Set this variable to 0 if you do not want any warnings printed. Personally I recommend against doing this,
but people asked for the option. Also, be advised that this is of course not threadsafe.
Defaults to 1.
So why is it not recommended? The answer seems to be: because
there is no other possibility to
handle certain errors! It's either a warning or nothing!
sub tar_error_reset { $Archive::Tar::error = ""; } sub tar_error { return $Archive::Tar::error ne ""; } sub tar_errormsg { return $Archive::Tar::error; } # Returns files extracted # Returns if an error is encountered. # The caller must use tar_error() to check for success! # The error message is available via tar_errormsg() # The files extracted so far can be deleted. sub tar_extract_all { my $tarfile = shift; my $tar = new Archive::Tar; tar_error_reset(); my $next = $tar->iter($tarfile); return () if (tar_error()); my @extracted; while (my $tarfile_object = $next->()) { $tarfile_object->extract() or last; last if (!defined $tarfile_object); push @extracted, $tarfile_object; last if (tar_error()); } return @extracted; }