Subject: | false positive "unreachable code" |
Date: | Tue, 15 May 2007 13:05:25 +0200 |
To: | bug-Perl-Critic [...] rt.cpan.org |
From: | Richard Jelinek <rj [...] petamem.com> |
With the following code, perlcritic complains about "Unreachable code"
at line 35 and line 51. I do not see any reason, why this should be
so.
Richard
--------------------
package File2;
use strict;
use warnings;
sub move_file {
my $from = shift; # ARG1: get source filename (path)
my $to = shift; # ARG2: get target filename (path)
my $ret = 1; # return value for successfull(1 = default)/unsuccessfull operation
return $ret if (rename($from, $to)); # return true, if on same filesystem (and moved)
if (open my $FROM, '<:raw', $from)) { # if source opened successfully
if (open my $TO, '>:raw', $to)) { # if target opened successfully
while(<$FROM>) { # iterate source and get content
print $TO; # write content to target
}
close $TO; # close target filehandle
}
else { # target file could not be opened
$ret = 0; # indicate error
}
close $FROM; # close source filehandle
}
if ($ret # if success in move
&& (-s $from == -s $to)) { # and source & target of same size
unlink($from); # remove source from filesystem
}
else { # something went wrong
unlink $to; # remove target file
$ret = 0; # set flag
}
return $ret; # indicate success/failure
} <------------------------------- HERE ????
sub write_file {
my $name = shift; # ARG1: get filename (path)
my $content = shift; # ARG2: get content (reference)
if (open my $DATA, '>:raw', $name) { # if open filename for writing ok
print $DATA $$content; # save content
close $DATA; # close filehandle
return 1; # indicate success
}
return; # indicate failure
}
1; <------------------------------- HERE ????
---------------