We all know that simple scalars can be chained together;

 

      $boolean = $this and $that or $the_other;

 

    I'm sure many of you have used Perl methods which return objects which

    you can use again in a chain like so:

 

      push @status_options, 'hidden' if

        GCt::glyph_attribute->retrieve(

            glyph_type => $glyph_type, 

            attr_name  => 'face_hideable'

            )

            ->attr_value;

 

    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

 

    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;

 

    Any feedback is appreciated.

 

_______________________________________________
sw-design mailing list
[EMAIL PROTECTED]
http://metaperl.com/cgi-bin/mailman/listinfo/sw-design

Reply via email to