File: uplevel-demo.pl

package info (click to toggle)
libsub-uplevel-perl 0.2800-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 260 kB
  • sloc: perl: 671; makefile: 2
file content (23 lines) | stat: -rw-r--r-- 538 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use strict;
use warnings;

use Sub::Uplevel;

# subroutine A calls subroutine B with uplevel(), so when
# subroutine B queries caller(), it gets main as the caller (just
# like subroutine A) instead of getting subroutine A

sub sub_a {
    print "Entering Subroutine A\n";
    print "caller() says: ", join( ", ", (caller())[0 .. 2] ), "\n";
    print "Calling B with uplevel\n";
    uplevel 1, \&sub_b;
}

sub sub_b {
    print "Entering Subroutine B\n";
    print "caller() says: ", join( ", ", (caller())[0 .. 2] ), "\n";
}

sub_a();