Subject: | Assumes all references filename are IO::Handle's instead of trying to stringify. |
Sample program showing the breakage: ( Given Getopt::Long
=========================================
use Archive::Tar;
package Foo;
sub new {
my $pkg = shift;
bless { @_ }, $pkg;
}
sub name {
my $self = shift;
''.$self->{name};
}
use overload '""' => \&name;
package main;
my $fname = Foo->new( name => shift );
print "Tar file: ", $fname, "\n";
my $next = Archive::Tar->iter( $fname );
while ( my $f = $next->() ) {
print "Tar member: ", $f->name, "\n";
}
1;
=========================================
Output ( given a tar file )
=========================================
prog my.tar
Tar file: my.tar
Can't locate object method "read" via package "Foo" at <(...sitepath...)
Show quoted text
>/lib/5.12.1/Archive/Tar.pm line 318.
=========================================
I've attached a possible patch. ( See also Bug #59149 )
Subject: | Archive-Tar.patch |
diff -U3 -r Archive-Tar-1.62/lib/Archive/Tar.pm Archive-Tar-1.62-patch/lib/Archive/Tar.pm
--- Archive-Tar-1.62/lib/Archive/Tar.pm 2010-06-28 16:50:19.000000000 -0400
+++ Archive-Tar-1.62-patch/lib/Archive/Tar.pm 2010-07-06 21:38:24.000000000 -0400
@@ -212,10 +212,15 @@
sub _get_handle {
my $self = shift;
my $file = shift; return unless defined $file;
- return $file if ref $file;
my $compress = shift || 0;
my $mode = shift || READ_ONLY->( ZLIB ); # default to read only
+ ### Check if file is a file handle or IO glob
+ if ( ref $file ) {
+ return $file if eval{ *$file{IO} };
+ return $file if eval{ $file->isa(q{IO::Handle}) };
+ $file = q{}.$file;
+ }
### get a FH opened to the right class, so we can use it transparently
### throughout the program
@@ -1246,7 +1251,12 @@
: do { seek $handle, 0, 0; local $/; <$handle> };
### make sure to close the handle if we created it
- close $handle unless ref($file);
+ if ( $file ne $handle ) {
+ unless( close $handle ) {
+ $self->_error( qq[Could not write tar] );
+ return;
+ }
+ }
return $rv;
}