Long::Jump(3pm) | User Contributed Perl Documentation | Long::Jump(3pm) |
Long::Jump - Mechanism for returning to a specific point from a deeply nested stack.
This module essentially provides a multi-level return. You can mark a spot with "setjump()" and then unwind the stack back to that point from any nested stack frame by name using "longjump()". You can also provide a list of return values.
This is not quite a match for C's long jump, but it is "close enough". It is safer than C's jump in that it only lets you escape frames by going up the stack, you cannot jump in other ways.
use Long::Jump qw/setjump longjump/; my $out = setjump foo => sub { bar(); ...; # Will never get here }; is($out, [qw/x y z/], "Got results of the long jump"); $out = setjump foo => sub { print "Not calling longjump"; }; is($out, undef, "longjump was not called so we got an undef response"); sub bar { baz(); return 'bar'; # Will never get here } sub baz { bat(); return 'baz'; # Will never get here } sub bat { my @out = qw/x y z/; longjump foo => @out; return 'bat'; # Will never get here }
The return value will always be false if "longjump" was not called, and will always be true if it was called.
You cannot nest multiple jump points with the same name, but you can nest multiple jump points if they have unqiue names. "longjump()" will always jump to the correct name.
The source code repository for Long-Jump can be found at https://github.com/exodist/Long-Jump/.
Copyright 2018 Chad Granum <exodist7@gmail.com>.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://dev.perl.org/licenses/
2023-01-27 | perl v5.36.0 |