Subject: | LWP::Protocol::collect() does not play nice with overloaded object files |
Here's a simple example.
use LWP::Simple;
use Path::Class;
$file = file("output.html");
print "HTTP Status: ".getstore("http://www.google.com", $file)."\n";
print "File exists" if -e $file;
The file is silently thrown away. It works fine if you force $file to
be a string.
The root of the problem is in LWP::Protocol::collect(). It checks if
the filename is not a reference. That won't play nice with stringified
objects.
Rather than trying to check if the thing is an object and it is string
overloaded, a simple solution is to make the else clause assume its a
file rather than (in this case ineffectually) dying. So...
if (!defined($arg) || !$response->is_success) {
...its that thing...
}
elsif (ref($arg) eq 'CODE') {
...its a code ref...
}
elsif( length($arg) ) {
...assume its a file...
}
else {
...die, we got an empty string...
}
If you hand it something weird and get a file called HASH(0x1398209), ok
fine.