Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Cutting repetition in POE coding

by robin (Chaplain)
on Nov 26, 2005 at 23:26 UTC ( #511961=note: print w/ replies, xml ) Need Help??


in reply to Cutting repetition in POE coding

It does sound rather as though you're looking for a way to make a sub force its caller to return. You may be interested, amused, and/or horrified to know that Want provides an (undocumented) way to do just this. If you call Want::double_return(), then the next ordinary return will return from the calling sub.

For example, the code:

use Want; sub foo { print "Entering foo\n"; bar(); print "Leaving foo\n"; return "foo did this"; } sub bar { print "Entering bar\n"; print "Leaving bar\n"; Want::double_return(); return "bar did this"; } print "About to call foo()\n"; my $r = foo(); print "foo() returned '$r'\n";
prints the following:
About to call foo() Entering foo Entering bar Leaving bar foo() returned 'bar did this'

Update: so in your case, you could write

sub EVENT { $kernel->post( shift, event => @_ ); Want::double_return(); return; }


Comment on Re: Cutting repetition in POE coding
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://511961]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-12-27 17:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls