Sometimes I use 'given' blocks to set a value. To save repeating myself
on the right hand side of the given block, I found I kept want to do this:

my $foo = given { }

...and have whatever value that was returned from when {} or default {}
populate $foo.

It turns out pugs already allow this, through the trick of wrapping the
given block in an anonymoose sub...which is then immediately executed:

my $rm = sub { given $rm_param {
        when Code  { $rm_param(self)   }
        when Hash  { %rm_param<run_mode> }
        default    { self.query.param($rm_param) }
    }}();

Not only do you get implicit matching on the left side, you get implicit
return values on the right!

I'd just like to be able to clean that up a little to:

my $rm = given $rm_param {
                when Code  { $rm_param(self)   }
                when Hash  { %rm_param<run_mode> }
                default    { self.query.param($rm_param) }
    };

   Mark

Reply via email to