Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 5203865d9be1c1df7ca400286e18a104 > files > 7

perl-Sub-Uplevel-0.22-1.fc13.noarch.rpm

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();