I have little actual experience with signal handlers, but as I understand you should do as little as possible in them and certainly avoid calling anything that might not be reentrant. The following may or may not work better than your current solution. YMMV.
my $is_break = 0;
$SIG{INT} = sub { $is_break = 1 };
my $result = is_success( getstore( $uri, $localfile ) );
if($is_break) {
print STDERR 'Removing incomplete download...';
-f $localfile and (
unlink $localfile
or print STDERR "\rCouldn't remove incompletely downloaded $lo
+calfile: $!\n"
);
}
exit $result;
Update: added file check as per
sauoq's post.
Makeshifts last the longest.