Package Info

perl-Hook-LexWrap


Lexically scoped subroutine wrappers


Development/Libraries/Perl

Hook::LexWrap allows you to install a pre- or post-wrapper (or both) around an existing subroutine. Unlike other modules that provide this capacity (e.g. Hook::PreAndPost and Hook::WrapSub), Hook::LexWrap implements wrappers in such a way that the standard 'caller' function works correctly within the wrapped subroutine.

To install a prewrappers, you write:

    use Hook::LexWrap;

    wrap 'subroutine_name', pre => \&some_other_sub;



The first argument to 'wrap' is a string containing the name of the subroutine to be wrapped (or the typeglob containing it, or a reference to it). The subroutine name may be qualified, and the subroutine must already be defined. The second argument indicates the type of wrapper being applied and must be either ''pre'' or ''post''. The third argument must be a reference to a subroutine that implements the wrapper.

To install a post-wrapper, you write:

    wrap 'subroutine_name', post => \&yet_another_sub;



To install both at once:

    wrap 'subroutine_name',
         pre  => \&some_other_sub,
         post => \&yet_another_sub;

or:

    wrap *subroutine_name,
         post => \&yet_another_sub,  # order in which wrappers are
         pre  => \&some_other_sub;   # specified doesn't matter

Once they are installed, the pre- and post-wrappers will be called before and after the subroutine itself, and will be passed the same argument list.

The pre- and post-wrappers and the original subroutine also all see the same (correct!) values from 'caller' and 'wantarray'.


License: Artistic-1.0 or GPL-1.0+
URL: http://search.cpan.org/dist/Hook-LexWrap/

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
0.26-bp155.2.12 info GA Release 2023-05-17 15 SP5
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Hook-LexWrap
0.26-bp154.1.24 info GA Release 2022-05-09 15 SP4
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Hook-LexWrap
0.26-bp153.1.15 info GA Release 2021-03-06 15 SP3
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Hook-LexWrap
0.26-bp152.3.18 info GA Release 2020-04-16 15 SP2
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Hook-LexWrap
0.26-bp151.3.1 info GA Release 2019-07-16 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Hook-LexWrap
0.26-bp151.2.14 info GA Release 2019-05-18 15 SP1
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Hook-LexWrap
0.26-bp150.2.4 info GA Release 2018-07-30 15
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-Hook-LexWrap