Larry Wall wrote:
> On Tue, Dec 04, 2007 at 08:40:10AM -0800, Jonathan Lang wrote:
> : or (I think):
> :
> :   method test ($value) {
> :     setup();
> :     when $value { doit() } #[smart-match the calling object $_ against 
> $value.]
> :   }
>
> I know it used to be that way back near the Dawn of Time, but methods
> don't automatically topicalize anymore unless you explicitly name
> one of the parameters '$_':

Huh.  I guess I need to review current standards for method
declaration; last I'd checked, the invocant did not need to be
explicitly named.

> : (Question: assuming that the above is valid, would breaking out of the
> : when block be the same as returning from the method?  Or would it
> : qualify as an abnormal termination of the method?)
>
> Well, according to S04:
>
>     "If the smart match succeeds, C<when>'s associated block is
>     executed, and the innermost surrounding block that has C<$_>
>     as one of its formal parameters (either explicit or implicit)
>     is automatically broken out of."

...which didn't answer my question, since "returning from the method"
and "having the method die" both qualify as breaking out of the method
in my mind.

> So it merely returns normally from the method, which is what you'd
> generally expect.

This makes sense to me.  Perhaps S04 could be updated to make this a
bit more explicit?  Also, can 'break' take a parameter?  My gut
instinct is "no"; if you want to break out of a method while
specifying a return value, you should probably use 'return' instead of
'break'.  Indeed, you may want to make this mandatory, much like the
conjecture about forcing people to use 'next' or 'last' instead of
'break' when in a loop.

-- 
Jonathan "Dataweaver" Lang

Reply via email to