I just now rewrote this method:

sub save_with_fetchable { my $self = shift; my @dirty = map { $_ => $_->fetchable->is_changed ? $_->fetchable : () } @_ $self->txn_do(sub { $_->insert_or_update() for @dirty }); }

sub save_with_fetchable { my ($self, @items) = @_; $self->txn_do(sub { for my $item (@items) { $item->insert_or_update; my $fetchable = $item->fetchable; $fetchable->insert_or_update if $fetchable->is_changed; } } ); }

... into:

... after Devel::Cover complained that my tests didn't exercise the $_->fetchable->is_changed branch condition in all of its forms. The tests indeed do exercise that, but I rewrote the code anyway.

Novice testers introduced to test code coverage often go through wild gyrations to make sure that every part of their code gets 100% coverage. Complete coverage is a good rule of thumb if and only if your tests exercise the intent of the code completely. It's relatively easy to exercise every statement and branch and conditional while letting trivial bugs go untested and unfixed.

With that said, code that's easy to test tends to be easier to verify and to maintain.

In this case, rewriting compact code—clever code—into something simple enough for D::C to verify makes the code easier to read. The design of the code is slightly better. Add to that the fact that the module containing this code now has 100% test coverage, so that any subsequent changes of coverage will have an obvious tie to subsequent changes of the code, and this was an easy decision to make.

It's nice when improving test coverage fixes bugs, but it's even nicer when improving test coverage leads to improving code and its design.