# man > B::Hooks::EndOfScope::PP

---
type: CommandReference
command: B::Hooks::EndOfScope::PP
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference
- `on_scope_end { ... }` — Register a block to execute after the surrounding scope has been compiled.
- `on_scope_end $code` — Register a code reference to execute after the surrounding scope has been compiled.

## Name
B::Hooks::EndOfScope::PP - Execute code after a scope finished compilation - PP implementation

## Synopsis
perl
use B::Hooks::EndOfScope::PP;
on_scope_end { ... };
on_scope_end $code;
## Description
This is the pure-perl implementation of `B::Hooks::EndOfScope` based only on modules available as part of the perl core. Its leaner sibling `B::Hooks::EndOfScope::XS` will be automatically preferred if all dependencies are available and the environment variable `B_HOOKS_ENDOFSCOPE_IMPLEMENTATION` is not set to 'PP'.

## Functions
- `on_scope_end { ... }` — Registers the code block to be executed after the surrounding scope has been compiled.
- `on_scope_end $code` — Registers the code reference to be executed after the surrounding scope has been compiled.
This function is exported by default. See [Sub::Exporter](http://localhost/phpMan.php/perldoc/Sub%3A%3AExporter/markdown) for customization.

## Examples
perl
use B::Hooks::EndOfScope::PP;
{
    my $var = 42;
    on_scope_end { print "Scope ended, var=$var\n" };
}
# Prints "Scope ended, var=42" after the block is compiled.
## See Also
- [B::Hooks::EndOfScope](http://localhost/phpMan.php/perldoc/B%3A%3AHooks%3A%3AEndOfScope/markdown) — general interface
- [B::Hooks::EndOfScope::XS](http://localhost/phpMan.php/perldoc/B%3A%3AHooks%3A%3AEndOfScope%3A%3AXS/markdown) — XS implementation (preferred if available)
- [Sub::Exporter](http://localhost/phpMan.php/perldoc/Sub%3A%3AExporter/markdown) — for customizing exports
- Report bugs via [RT: B-Hooks-EndOfScope](https://rt.cpan.org/Public/Dist/Display.html?Name=B-Hooks-EndOfScope) or <bug-B-Hooks-EndOfScope@rt.cpan.org>

## Exit Codes
(Not documented)