Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / B / Hooks / EndOfScope.pm
CommitLineData
3fea05b9 1use strict;
2use warnings;
3
4package B::Hooks::EndOfScope;
5
6use 5.008000;
7use Variable::Magic;
8
9our $VERSION = '0.08';
10
11use Sub::Exporter -setup => {
12 exports => ['on_scope_end'],
13 groups => { default => ['on_scope_end'] },
14};
15
16=head1 NAME
17
18B::Hooks::EndOfScope - Execute code after a scope finished compilation
19
20=head1 SYNOPSIS
21
22 on_scope_end { ... };
23
24=head1 DESCRIPTION
25
26This module allows you to execute code when perl finished compiling the
27surrounding scope.
28
29=head1 FUNCTIONS
30
31=head2 on_scope_end
32
33 on_scope_end { ... };
34
35 on_scope_end $code;
36
37Registers C<$code> to be executed after the surrounding scope has been
38compiled.
39
40This is exported by default. See L<Sub::Exporter> on how to customize it.
41
42=cut
43
44{
45 my $wiz = Variable::Magic::wizard
46 data => sub { [$_[1]] },
47 free => sub { $_->() for @{ $_[1] }; () };
48
49 sub on_scope_end (&) {
50 my $cb = shift;
51
52 $^H |= 0x020000;
53
54 if (my $stack = Variable::Magic::getdata %^H, $wiz) {
55 push @{ $stack }, $cb;
56 }
57 else {
58 Variable::Magic::cast %^H, $wiz, $cb;
59 }
60 }
61}
62
63=head1 SEE ALSO
64
65L<Sub::Exporter>
66
67L<Variable::Magic>
68
69=head1 AUTHOR
70
71Florian Ragwitz E<lt>rafl@debian.orgE<gt>
72
73=head1 COPYRIGHT AND LICENSE
74
75Copyright (c) 2008 Florian Ragwitz
76
77This module is free software.
78
79You may distribute this code under the same terms as Perl itself.
80
81=cut
82
831;