Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re^3: Finding the end of a method-chain

by Eily (Prior)
on Nov 07, 2013 at 14:09 UTC ( #1061574=note: print w/replies, xml ) Need Help??

in reply to Re^2: Finding the end of a method-chain
in thread Finding the end of a method-chain

Alright, I should have seen that, or at least tried it. The problem is that create is called before join (obviously) so the way the return of join will be used is unknown at that time. threads allows you to indicate in which context you want your sub to be called (void, scalar or list) (and if you didn't know that, you probably always called your sub in a scalar context), but not to indicate what will be done of the returned value(s).

Unless the sub passed as a parameter to threads->create can be your tail method, you could just check (caller 1)[3] eq '(eval)' before trying to use want.

If this sub can be your tail method, be sure to add {'void' => 1} as the first parameter to threads->create when you're not going to use the return of join(). Then you could have: print " ..and Im a tail!\n" unless defined wantarray and want "OBJECT"

This is probably a bad idea if you want to be able to use the return value of your method, which can be called by thread->create, and can be the tail method. Why are trying to do that by the way? Maybe you've just set foot on a XY Problem and could avoid using want altogether.

Replies are listed 'Best First'.
Re^4: Finding the end of a method-chain
by std3rr (Novice) on Nov 08, 2013 at 14:05 UTC

    The oneliner was just a simple reproduction of the segfault, not that I wanted to get anything else out of it.

    I like the abillity to decide what to return depending on where Im at in the chain. You can have polyfunctional methods with same name returning diffrent depending on this.
    Not that I 'must' do this or cant solve this programming structure/functionality in any other way(hey, this is perl ;), but I liked the ability.

    It would be cool to have a "caller"-function for these chains, but as I guess the stack doesnt gets pushed an popped in the same manner, so its trickier.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1061574]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2018-05-20 22:40 GMT
Find Nodes?
    Voting Booth?