[Pdx-pm] Test::Builder calling convention

Hans Dieter Pearcey hdp.perl.pm.pdx at weftsoar.net
Fri Mar 13 12:08:38 PDT 2009


On Fri, Mar 13, 2009 at 11:51:04AM -0700, Michael G Schwern wrote:
> As always, +1 and -1s appreciated.

+1

> PS  At PDX.pm we talked about an or() method which would do this:
> 
>     $builder->ok( open my $fh, $file )
>             ->diag( "Errno: $!" )
>             ->or
>             ->is( $!, ENOBACON )
>             ->name( "Insufficient bacon" );
> 
> Its a short circuit method.  If the result is true, it returns a null object
> that does nothing.  If it's false, it chains the result through and the
> following is() starts a new result object.  Trouble is, I can't remember what
> it bought us over a regular or operator.
> 
>     $builder->ok( open my $fh, $file )
>             ->diag( "Errno: $!" )
>       or
>     $builder->is( $!, ENOBACON )
>             ->name( "Insufficient bacon" );
> 
> That would appear to be perfectly sufficient, understandable to all and you
> get real short circuiting, not calling empty methods on an empty object.

It seems weird to me that diag() in your second example is returning whether or
not the test passed.

The whole example is a little contrived, though.  Do you really want to run a
second test based on whether the first passed?  It's hard to consider this
syntax without a real use case.

hdp.


More information about the Pdx-pm-list mailing list