Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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; }

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2023-12-04 08:47 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (23 votes). Check out past polls.