Re: short-circuiting method conjunction?

[prev] [thread] [next] [Date index for 2004/11/24]

From: Tim Bunce
Subject: Re: short-circuiting method conjunction?
Date: 10:06 on 24 Nov 2004
On Tue, Nov 23, 2004 at 02:40:04PM -0800, Terrence Brannon wrote:
>        We all know that simple scalars can be chained together;
> 
>          $boolean = $this and $that or $the_other;

That's   (($boolean = $this) and $that) or $the_other;

which probably isn't what you meant and would give a "Useless use
of a variable in void context" warning :)

>        It would be neat if there were some method-chaining syntax/module which
>        indicated "return false if your method call returns false":
> 
>           $object-?->method1-?->method2-?->method3
> 
>        One solution appears to be Pipeline:
> 
>                http://search.cpan.org/~rclamp/Pipeline-3.12/lib/Pipeline.pm

Er, I don't think so, but even if it is, that's a massive sledgehammer
for this very small nut.

>        What I currently do is wrap the method chain in an eval block and check
>        to see if a Boolean was set within the block:
> 
>         {
>          my $boolean;
> 
>          eval {
>            $boolean =
>              GCt::glyph_attribute->retrieve
>                  (
>                   glyph_type => $glyph_type, 
>                   attr_name  => 'face_hideable'
>                  )
>                    ->attr_value;
>          }
>         }
> 
>        push @status_options, 'hidden' if $boolean;
>        but that is much wordier than:
> 
>          push @status_options, 'hidden' if
>            GCt::glyph_attribute-?->retrieve(
>                glyph_type => $glyph_type, 
>                attr_name  => 'face_hideable'
>                )
>                -?->attr_value;

This seems just fine to me:

           push @status_options, 'hidden' if eval {
             GCt::glyph_attribute->retrieve(
                 glyph_type => $glyph_type, 
                 attr_name  => 'face_hideable'
                 )
                 ->attr_value };

Tim.

short-circuiting method conjunction?
Terrence Brannon 22:40 on 23 Nov 2004

Re: short-circuiting method conjunction?
Tim Bunce 10:06 on 24 Nov 2004

Generated at 11:34 on 01 Dec 2004 by mariachi v0.52