[Pdx-pm] the quest for return_if

benh ben.hengst at gmail.com
Tue Jun 26 16:03:18 PDT 2007


so at work I'm trying to clean up this big decision tree and I came up
with the idea to have a return_if sub... seems easy, looks clean. The
plan was to take this big waterfall if-else block and start to invert
the logic a bit to clean things up... this would help to reduce things
to nice clean, easy to read lines. Alas I'm horribly lost and figured
I would enlist some help.

Ideally I would love to do this:

sub return_if {
   my ($eval, $value) = @_;
   $value = $eval if !defined($value);
   {FROM_THE_POINT_WHERE_I_WAS_CALLED}->return $value if defined($eval);
}

The hard part for me is getting a sub to issue a return from where it
was called from? I asked on #perl and ended up getting pointed to:
Code::Splice
Sub::WrapPackages
Hook::LexWrap

The problem is that all of these basically just inject pre and post
actions to a sub... so I still can't think of how to have return_if
issue a return at the point where it's called?

Am I just dreaming? is this not possible? It's not like it's all that
hard to just write it out long hand and it's not the end of the world
if this is not possible, just one of the sticky points for the day.
Figured I would share.

-- 
benh~


More information about the Pdx-pm-list mailing list