in reply to Contextual::Return blocks: can they be made to return the actual result?

No; Contextual::Return always returns a Contextual::Return::Value object in scalar context. That's part of the mechanism that allows it to work; when the function is running it can't predict, say, whether the result will be used as a string or a boolean, so it returns an object that overloads both.

If $foo is an object, you shouldn't be peeking at $foo->{name} anyway; write an accessor so that you can do $foo->name.

If you're after wantarray-on-crack, then Want might be more to your liking.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^2: Contextual::Return blocks: can they be made to return the actual result?
by wanna_code_perl (Friar) on Jul 14, 2013 at 03:00 UTC
    If $foo is an object, you shouldn't be peeking at $foo->{name} anyway; write an accessor so that you can do $foo->name.

    Funny you should mention that. That's precisely what I was trying to do when I first saw the "DEFAULT block did not return a suitable reference to the hash dereference at ...". I decided it wasn't worth it a short time later, but it was starting to look like I'd have to implement most of the class inside one of Contextual::Return's METHOD { ... } blocks.

    You're spot on, though. If I use anything, it'll probably be Want.