Michael G Schwern wrote:

The other examples in the ticket play out the same way:

        bless {}, ref $class || $class;


I encountered the coverage problem inherent in this code in the constructor of a module whose maintenance I recently assumed. (For that matter, I could have encountered it in modules I myself wrote and still maintain.) I eventually figured that there was no reasonable way to make the "red" in the top line of the condition box go away. And since that was the last remaining bit of uncovered code within the constructor, I figured I should clean that up as well. So I re-coded along these lines:

    my $self = ref($class) ? bless( {}, ref($class) )
                           : bless( {}, $class );

More verbose. Less elegant. But more strictly precise. And 100% testable with reasonable conditions.

jimk

Reply via email to