1Long::Jump(3)         User Contributed Perl Documentation        Long::Jump(3)
2
3
4

NAME

6       Long::Jump - Mechanism for returning to a specific point from a deeply
7       nested stack.
8

DESCRIPTION

10       This module essentially provides a multi-level return. You can mark a
11       spot with setjump() and then unwind the stack back to that point from
12       any nested stack frame by name using longjump(). You can also provide a
13       list of return values.
14
15       This is not quite a match for C's long jump, but it is "close enough".
16       It is safer than C's jump in that it only lets you escape frames by
17       going up the stack, you cannot jump in other ways.
18

SYNOPSIS

20           use Long::Jump qw/setjump longjump/;
21
22           my $out = setjump foo => sub {
23               bar();
24               ...; # Will never get here
25           };
26           is($out, [qw/x y z/], "Got results of the long jump");
27
28           $out = setjump foo => sub {
29               print "Not calling longjump";
30           };
31           is($out, undef, "longjump was not called so we got an undef response");
32
33           sub bar {
34               baz();
35               return 'bar'; # Will never get here
36           }
37
38           sub baz {
39               bat();
40               return 'baz'; # Will never get here
41           }
42
43           sub bat {
44               my @out = qw/x y z/;
45               longjump foo => @out;
46
47               return 'bat'; # Will never get here
48           }
49

EXPORTS

51       $out = setjump($NAME, sub { ... })
52       $out = setjump $NAME, sub { ... }
53       $out = setjump($NAME => sub { ... })
54       $out = setjump $NAME => sub { ... }
55           Set a named point to which you will return when calling longjump().
56           $out will be "undef" if longjump() was not called. $out will be an
57           arrayref if longjump() was called. The $out arrayref will be empty,
58           but present if longjump() is called without any return values.
59
60           The return value will always be false if "longjump" was not called,
61           and will always be true if it was called.
62
63           You cannot nest multiple jump points with the same name, but you
64           can nest multiple jump points if they have unqiue names. longjump()
65           will always jump to the correct name.
66
67       longjump($NAME)
68       longjump $NAME
69       longjump($NAME, @RETURN_LIST)
70       longjump($NAME => @RETURN_LIST)
71       longjump $NAME => @RETURN_LIST
72           Jump to the named point, optionally with values to return. This
73           will throw exceptions if you use an invalid $NAME, which includes
74           the case of calling it without a set jump point.
75

SOURCE

77       The source code repository for Long-Jump can be found at
78       https://github.com/exodist/Long-Jump/.
79

MAINTAINERS

81       Chad Granum <exodist@cpan.org>
82

AUTHORS

84       Chad Granum <exodist@cpan.org>
85
87       Copyright 2018 Chad Granum <exodist7@gmail.com>.
88
89       This program is free software; you can redistribute it and/or modify it
90       under the same terms as Perl itself.
91
92       See http://dev.perl.org/licenses/
93
94
95
96perl v5.36.0                      2023-01-20                     Long::Jump(3)
Impressum