in reply to Devel::Cover and impossible codepaths

I wonder if it gives a problem for
my $var = ( $opts->{foo} or $self->{default_foo} );

Replies are listed 'Best First'.
Re^2: Devel::Cover and impossible codepaths
by Tanktalus (Canon) on Nov 16, 2009 at 15:02 UTC

    Thanks, but this one doesn't solve the issue - I don't think you're surprised by the fact that at the end of the day, || and or probably both use the same opcodes, so they're going to result in the same codepaths to Devel::Cover. The other solutions result in things that look like they might take longer (didn't benchmark yet to be sure), especially since $opts->{foo} really is $self->get_field($opt->{field})->{foo}, so, even if get_field is O(N), it has a significantly higher constant, and so evaluating it twice is an annoyance I'd prefer not to embrace. The || idiom is really perfect here from a readability, maintainability, and speed perspective. It just isn't what Devel::Cover seems to like.

    This is why I was hoping for some generic way to tell Devel::Cover to ignore a certain case. e.g., something like:

    ### Devel::Cover: 0 0 ### I know that $self->{default_foo} is neve +r false. my $var = $opts->{foo} || $self->{default_foo};
    I guess my alternative is to stop initialising default_foo in the constructor, and have that as a fall-back here:
    my $var = $opts->{foo} || $self->{default_foo} || "default value";
    Maybe Devel::Cover will be able to see there is no way for the last option to be false, and omit it. But then if I want to have a get-routine that gets its current default_foo, I'd have this default in two places, and that is one of the evils I am constantly battling at $work already, so I don't want to go down that road.

      my $var = $opts->{foo} || $self->{default_foo} || "PLACATE DEVEL::COVE +R";

      Update: Never mind, that doesn't help. It's still going to expect the second condition to be false in some test.