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.


In reply to Re^2: Devel::Cover and impossible codepaths by Tanktalus
in thread Devel::Cover and impossible codepaths by Tanktalus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.