MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //usr/local/ssl/local/share/man/man3/Sub::Uplevel.3
.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings.  \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote.  | will give a
.\" real vertical bar.  \*(C+ will give a nicer C++.  Capital omega is used to
.\" do unbreakable dashes and therefore won't be available.  \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
.    ds -- \(*W-
.    ds PI pi
.    if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.    if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\"  diablo 12 pitch
.    ds L" ""
.    ds R" ""
.    ds C` ""
.    ds C' ""
'br\}
.el\{\
.    ds -- \|\(em\|
.    ds PI \(*p
.    ds L" ``
.    ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD.  Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
.    de IX
.    tm Index:\\$1\t\\n%\t"\\$2"
..
.    nr % 0
.    rr F
.\}
.\"
.\" For nroff, turn off justification.  Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear.  Run.  Save yourself.  No user-serviceable parts.
.    \" fudge factors for nroff and troff
.if n \{\
.    ds #H 0
.    ds #V .8m
.    ds #F .3m
.    ds #[ \f1
.    ds #] \fP
.\}
.if t \{\
.    ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.    ds #V .6m
.    ds #F 0
.    ds #[ \&
.    ds #] \&
.\}
.    \" simple accents for nroff and troff
.if n \{\
.    ds ' \&
.    ds ` \&
.    ds ^ \&
.    ds , \&
.    ds ~ ~
.    ds /
.\}
.if t \{\
.    ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.    ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.    ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.    ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.    ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.    ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
.    \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.    \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.    \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.    ds : e
.    ds 8 ss
.    ds o a
.    ds d- d\h'-1'\(ga
.    ds D- D\h'-1'\(hy
.    ds th \o'bp'
.    ds Th \o'LP'
.    ds ae ae
.    ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Sub::Uplevel 3"
.TH Sub::Uplevel 3 "2009-11-17" "perl v5.8.8" "User Contributed Perl Documentation"
.SH "NAME"
Sub::Uplevel \- apparently run a function in a higher stack frame
.SH "VERSION"
.IX Header "VERSION"
This documentation describes version 0.22
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\&  use Sub::Uplevel;
.Ve
.PP
.Vb 3
\&  sub foo {
\&      print join " - ", caller;
\&  }
.Ve
.PP
.Vb 3
\&  sub bar {
\&      uplevel 1, \e&foo;
\&  }
.Ve
.PP
.Vb 2
\&  #line 11
\&  bar();    # main - foo.plx - 11
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
Like Tcl's \fIuplevel()\fR function, but not quite so dangerous.  The idea
is just to fool \fIcaller()\fR.  All the really naughty bits of Tcl's
\&\fIuplevel()\fR are avoided.
.PP
\&\fB\s-1THIS\s0 \s-1IS\s0 \s-1NOT\s0 \s-1THE\s0 \s-1SORT\s0 \s-1OF\s0 \s-1THING\s0 \s-1YOU\s0 \s-1WANT\s0 \s-1TO\s0 \s-1DO\s0 \s-1EVERYDAY\s0\fR
.IP "\fBuplevel\fR" 4
.IX Item "uplevel"
.Vb 1
\&  uplevel $num_frames, \e&func, @args;
.Ve
.Sp
Makes the given function think it's being executed \f(CW$num_frames\fR higher
than the current stack level.  So when they use caller($frames) it
will actually give caller($frames + \f(CW$num_frames\fR) for them.
.Sp
\&\f(CW\*(C`uplevel(1, \e&some_func, @_)\*(C'\fR is effectively \f(CW\*(C`goto &some_func\*(C'\fR but
you don't immediately exit the current subroutine.  So while you can't
do this:
.Sp
.Vb 5
\&    sub wrapper {
\&        print "Before\en";
\&        goto &some_func;
\&        print "After\en";
\&    }
.Ve
.Sp
you can do this:
.Sp
.Vb 6
\&    sub wrapper {
\&        print "Before\en";
\&        my @out = uplevel 1, &some_func;
\&        print "After\en";
\&        return @out;
\&    }
.Ve
.Sp
\&\f(CW\*(C`uplevel\*(C'\fR will issue a warning if \f(CW$num_frames\fR is more than the current call
stack depth.
.SH "EXAMPLE"
.IX Header "EXAMPLE"
The main reason I wrote this module is so I could write wrappers
around functions and they wouldn't be aware they've been wrapped.
.PP
.Vb 1
\&    use Sub::Uplevel;
.Ve
.PP
.Vb 1
\&    my $original_foo = \e&foo;
.Ve
.PP
.Vb 5
\&    *foo = sub {
\&        my @output = uplevel 1, $original_foo;
\&        print "foo() returned:  @output";
\&        return @output;
\&    };
.Ve
.PP
If this code frightens you \fByou should not use this module.\fR
.SH "BUGS and CAVEATS"
.IX Header "BUGS and CAVEATS"
Well, the bad news is \fIuplevel()\fR is about 5 times slower than a normal
function call.  \s-1XS\s0 implementation anyone?  It also slows down every invocation
of \fIcaller()\fR, regardless of whether \fIuplevel()\fR is in effect.
.PP
Sub::Uplevel overrides CORE::GLOBAL::caller temporarily for the scope of
each uplevel call.  It does its best to work with any previously existing
CORE::GLOBAL::caller (both when Sub::Uplevel is first loaded and within 
each uplevel call) such as from Contextual::Return or Hook::LexWrap.  
.PP
However, if you are routinely using multiple modules that override 
CORE::GLOBAL::caller, you are probably asking for trouble.
.PP
You \fBshould\fR load Sub::Uplevel as early as possible within your program.  As
with all \s-1CORE::GLOBAL\s0 overloading, the overload will not affect modules that
have already been compiled prior to the overload.  One module that often is
unavoidably loaded prior to Sub::Uplevel is Exporter.  To forceably recompile
Exporter (and Exporter::Heavy) after loading Sub::Uplevel, use it with the
\&\*(L":aggressive\*(R" tag:
.PP
.Vb 1
\&    use Sub::Uplevel qw/:aggressive/;
.Ve
.PP
The private function \f(CW\*(C`Sub::Uplevel::_force_reload()\*(C'\fR may be passed a list of
additional modules to reload if \*(L":aggressive\*(R" is not aggressive enough.  
Reloading modules may break things, so only use this as a last resort.
.PP
As of version 0.20, Sub::Uplevel requires Perl 5.6 or greater.
.SH "HISTORY"
.IX Header "HISTORY"
Those who do not learn from \s-1HISTORY\s0 are doomed to repeat it.
.PP
The lesson here is simple:  Don't sit next to a Tcl programmer at the
dinner table.
.SH "THANKS"
.IX Header "THANKS"
Thanks to Brent Welch, Damian Conway and Robin Houston.
.SH "AUTHORS"
.IX Header "AUTHORS"
David A Golden <dagolden@cpan.org> (current maintainer)
.PP
Michael G Schwern <schwern@pobox.com> (original author)
.SH "LICENSE"
.IX Header "LICENSE"
Original code Copyright (c) 2001 to 2007 by Michael G Schwern.
Additional code Copyright (c) 2006 to 2008 by David A Golden.
.PP
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
.PP
See http://www.perl.com/perl/misc/Artistic.html
.SH "SEE ALSO"
.IX Header "SEE ALSO"
PadWalker (for the similar idea with lexicals), Hook::LexWrap, 
Tcl's \fIuplevel()\fR at http://www.scriptics.com/man/tcl8.4/TclCmd/uplevel.htm