Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Cutting repetition in POE coding

by robin (Chaplain)
on Nov 26, 2005 at 23:26 UTC ( [id://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; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-23 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found