Acme::Sub::Fallback - Fall back to subs in stack


NAME

Acme::Sub::Fallback - Fall back to subs in stack


SYNOPSIS

 use Acme::Sub::Fallback qw(fallback);
 # do NOT use this code
 init();
 sub init {
     $i = 0;
     increase();
 }
 sub increase {
     print ++$i,"\n";
     loop();
 }
 sub loop { 
     fallback(0)       if $i == 20;    # falls back to init()
     fallback(1,1);                    # falls back to increase() in 1 sec
 }


FUNCTIONS

fallback

Falls back to previously executed subs in stack.

 fallback( stack frame, [sec] );

Unlike perl's caller, fallback() takes an absolute integer as level indicator. 0 does always refer to the first stack frame. fallback(0) will thus fall back to the first sub within the stack. A sleep interval (sec) before falling back may be provided.


EXPORT

fallback() is exportable.


CAVEATS

Speed may become an issue since a counter has to be incremented to keep count of stack frames.


SEE ALSO

caller in the perlfunc manpage

 Acme::Sub::Fallback - Fall back to subs in stack