On Tue, Jul 12, 2005 at 10:44:02PM -0400, James E Keenan 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.

I would have just eliminated the $obj->new option.  In all my years of
programming Perl I've never used it nor have I recently seen it used.
Pure YAGNI.

        bless {}, $class;


-- 
Michael G Schwern     [EMAIL PROTECTED]     http://www.pobox.com/~schwern
'All anyone gets in a mirror is themselves,' she said. 'But what you
gets in a good gumbo is everything.'
        -- "Witches Abroad" by Terry Prachett

Reply via email to