Long::Jump(3pm)
π¦ Long::Jump π¦
okay so picture this: you're deep, deep in a nested stack, like ten frames down, and you just need to get all the way back to one specific spot. that's literally what this page is about, bestie. this is Long::Jump, from the User Contributed Perl Documentation section, and it's giving "multi-level return, but make it safe". π
β¨ NAME β¨
Long::Jump β a whole mechanism for returning to a specific point from a deeply nested stack. no cap.
πΈ DESCRIPTION πΈ
so like, this module essentially provides a multi-level return. that's the vibe. π
here's the tea: you mark a spot with setjump(), and then from literally any nested stack frame you can unwind the stack back to that point by name using longjump(). the name is how it finds its way home, iykyk. you can also hand it a list of return values on the way back, which is iconic of it honestly.
it's not quite a match for C's long jump, but it is "close enough". and it's actually safer than C's jump, because it only lets you escape frames by going up the stack β you cannot jump in other ways. no sneaky sideways jumps, no chaos, just vibes and a one-way trip upward. π§
β SYNOPSIS β
like, here's the whole thing in action. she's beautiful:
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
}
notice all those # Will never get here comments? yeah. they really will never get here. that's the whole point. π
π EXPORTS π
π« setjump
$out = setjump($NAME, sub { ... })
$out = setjump $NAME, sub { ... }
$out = setjump($NAME => sub { ... })
$out = setjump $NAME => sub { ... }
set a named point to which you will return when calling longjump(). periodt.
$outwill beundefiflongjump()was not called. π΄$outwill be an arrayref iflongjump()was called. π₯- that
$outarrayref will be empty, but present, iflongjump()is called without any return values. (empty but present, she's still there, she's just not saying anything β¨)
the return value will always be false if longjump was not called, and will always be true if it was called. so like, truthiness is your status report, bestie.
you cannot nest multiple jump points with the same name β that's not allowed, don't do it. but you can nest multiple jump points if they have unique names, and longjump() will always jump to the correct name. she knows exactly which one you mean. π
π« longjump
longjump($NAME)
longjump $NAME
longjump($NAME, @RETURN_LIST)
longjump($NAME => @RETURN_LIST)
longjump $NAME => @RETURN_LIST
jump to the named point, optionally bringing values along to return. that's the moment. π
β οΈ bestie listen β this will throw exceptions if you use an invalid $NAME. and yes, that includes the case of calling it without a set jump point. so like, know your names or she's gonna yell.
π« havejump
$bool = havejump($NAME)
$bool = havejump $NAME
check if a jump point with the given $NAME is currently set somewhere on the call stack. π
- returns a true value (
1) if the named jump point is active and would be reachable vialongjump($NAME) - otherwise returns false (
0)
this is so useful for code that wants to conditionally call longjump() only when an enclosing setjump() is actually present β because that avoids the exception that would be thrown for an unknown name. it's the "look before you leap" of the group chat. π«Ά
π SOURCE π
the source code repository for Long-Jump can be found at https://github.com/exodist/Long-Jump/. go be nosy, she's open source, she's generous. π
π MAINTAINERS π
Chad Granum <exodist@cpan.org>
π AUTHORS π
Chad Granum <exodist@cpan.org>
π COPYRIGHT π
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/
and that's the whole page, bestie!! π¦ this was perl v5.40.1, dated 2026-05-08, and it's the Long::Jump(3pm) page β now go forth and jump responsibly, no cap. π
β¨πΈ
π¦ where this page comes from
- ubuntu stonking: liblong-jump-perl 0.000005-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms