# phpman > perldoc > B::Hooks::EndOfScope

## NAME
    [B::Hooks::EndOfScope](https://www.chedong.com/phpMan.php/perldoc/B%3A%3AHooks%3A%3AEndOfScope/markdown) - Execute code after a scope finished compilation

## VERSION
    version 0.25

## SYNOPSIS
        on_scope_end { ... };

## DESCRIPTION
    This module allows you to execute code when perl finished compiling the surrounding scope.

## FUNCTIONS
  on_scope_end
        on_scope_end { ... };

        on_scope_end $code;

    Registers $code to be executed after the surrounding scope has been compiled.

    This is exported by default. See [Sub::Exporter](https://www.chedong.com/phpMan.php/perldoc/Sub%3A%3AExporter/markdown) on how to customize it.

## LIMITATIONS
### Pure-perl mode caveat
    This caveat applies to any version of perl where [Variable::Magic](https://www.chedong.com/phpMan.php/perldoc/Variable%3A%3AMagic/markdown) is unavailable or otherwise
    disabled.

    While [Variable::Magic](https://www.chedong.com/phpMan.php/perldoc/Variable%3A%3AMagic/markdown) has access to some very dark sorcery to make it possible to throw an
    exception from within a callback, the pure-perl implementation does not have access to these
    hacks. Therefore, what would have been a compile-time exception is instead converted to a
    warning, and your execution will continue as if the exception never happened.

    To explicitly request an XS (or PP) implementation one has two choices. Either to import from
    the desired implementation explicitly:

     use [B::Hooks::EndOfScope::XS](https://www.chedong.com/phpMan.php/perldoc/B%3A%3AHooks%3A%3AEndOfScope%3A%3AXS/markdown)
       or
     use [B::Hooks::EndOfScope::PP](https://www.chedong.com/phpMan.php/perldoc/B%3A%3AHooks%3A%3AEndOfScope%3A%3APP/markdown)

    or by setting $ENV{B_HOOKS_ENDOFSCOPE_IMPLEMENTATION} to either "XS" or "PP".

  Perl 5.8.0 ~ 5.8.3
    Due to a core interpreter bug <<https://rt.perl.org/Public/Bug/Display.html?id=27040#txn-82797>>
    present in older perl versions, the implementation of [B::Hooks::EndOfScope](https://www.chedong.com/phpMan.php/perldoc/B%3A%3AHooks%3A%3AEndOfScope/markdown) deliberately leaks a
    single empty hash for every scope being cleaned. This is done to avoid the memory corruption
    associated with the bug mentioned above.

    In order to stabilize this workaround use of [Variable::Magic](https://www.chedong.com/phpMan.php/perldoc/Variable%3A%3AMagic/markdown) is disabled on perls prior to
    version 5.8.4. On such systems loading/requesting [B::Hooks::EndOfScope::XS](https://www.chedong.com/phpMan.php/perldoc/B%3A%3AHooks%3A%3AEndOfScope%3A%3AXS/markdown) explicitly will
    result in a compile-time exception.

### Perl versions 5.6.x
    Versions of perl before 5.8.0 lack a feature allowing changing the visibility of "%^H" via
    setting bit 17 within $^H. As such the only way to achieve the effect necessary for this module
    to work, is to use the "local" operator explicitly on these platforms. This might lead to
    unexpected interference with other scope-driven libraries relying on the same mechanism. On the
    flip side there are no such known incompatibilities at the time this note was written.

    For further details on the unavailable behavior please refer to the test file t/02-localise.t
    included with the distribution.

## SEE ALSO
    [Sub::Exporter](https://www.chedong.com/phpMan.php/perldoc/Sub%3A%3AExporter/markdown)

    [Variable::Magic](https://www.chedong.com/phpMan.php/perldoc/Variable%3A%3AMagic/markdown)

## SUPPORT
    Bugs may be submitted through the RT bug tracker
    <<https://rt.cpan.org/Public/Dist/Display.html?Name=B-Hooks-EndOfScope>> (or
    <bug-B-Hooks-EndOfScope@rt.cpan.org> <mailto:<bug-B-Hooks-EndOfScope@rt.cpan.org>>).

## AUTHORS
    *   Florian Ragwitz <<rafl@debian.org>>

    *   Peter Rabbitson <<ribasushi@leporine.io>>

## CONTRIBUTORS
    *   Karen Etheridge <<ether@cpan.org>>

    *   Christian Walde <<walde.christian@googlemail.com>>

    *   Graham Knop <<haarg@haarg.org>>

    *   Simon Wilper <<sxw@chronowerks.de>>

    *   Tatsuhiko Miyagawa <<miyagawa@bulknews.net>>

    *   Tomas Doran <<bobtfish@bobtfish.net>>

## COPYRIGHT AND LICENCE
    This software is copyright (c) 2008 by Florian Ragwitz.

    This is free software; you can redistribute it and/or modify it under the same terms as the Perl
    5 programming language system itself.

