| Filename | /usr/share/perl5/B/Hooks/EndOfScope/XS.pm | 
| Statements | Executed 0 statements in 0s | 
| Line | State ments | Time on line | Calls | Time in subs | Code | 
|---|---|---|---|---|---|
| 1 | package B::Hooks::EndOfScope::XS; | ||||
| 2 | { | ||||
| 3 | $B::Hooks::EndOfScope::XS::VERSION = '0.13'; | ||||
| 4 | } | ||||
| 5 | BEGIN { | ||||
| 6 | $B::Hooks::EndOfScope::XS::AUTHORITY = 'cpan:FLORA'; | ||||
| 7 | } | ||||
| 8 | # ABSTRACT: Execute code after a scope finished compilation - XS implementation | ||||
| 9 | |||||
| 10 | use strict; | ||||
| 11 | use warnings; | ||||
| 12 | |||||
| 13 | BEGIN { | ||||
| 14 | require Module::Runtime; | ||||
| 15 | # Adjust the Makefile.PL if changing this minimum version | ||||
| 16 | Module::Runtime::use_module('Variable::Magic', '0.48'); | ||||
| 17 | } | ||||
| 18 | |||||
| 19 | use Sub::Exporter::Progressive -setup => { | ||||
| 20 | exports => ['on_scope_end'], | ||||
| 21 | groups => { default => ['on_scope_end'] }, | ||||
| 22 | }; | ||||
| 23 | |||||
| 24 | my $wiz = Variable::Magic::wizard | ||||
| 25 | data => sub { [$_[1]] }, | ||||
| 26 | free => sub { $_->() for @{ $_[1] }; () }, | ||||
| 27 | # When someone localise %^H, our magic doesn't want to be copied | ||||
| 28 | # down. We want it to be around only for the scope we've initially | ||||
| 29 | # attached ourselfs to. Merely having MGf_LOCAL and a noop svt_local | ||||
| 30 | # callback achieves this. If anything wants to attach more magic of our | ||||
| 31 | # kind to a localised %^H, things will continue to just work as we'll be | ||||
| 32 | # attached with a new and empty callback list. | ||||
| 33 | local => \undef | ||||
| 34 | ; | ||||
| 35 | |||||
| 36 | sub on_scope_end (&) { | ||||
| 37 | my $cb = shift; | ||||
| 38 | |||||
| 39 | $^H |= 0x020000; | ||||
| 40 | |||||
| 41 | if (my $stack = Variable::Magic::getdata %^H, $wiz) { | ||||
| 42 | push @{ $stack }, $cb; | ||||
| 43 | } | ||||
| 44 | else { | ||||
| 45 | 26 | 74µs | Variable::Magic::cast %^H, $wiz, $cb;     # spent    74µs making 26 calls to B::Hooks::EndOfScope::XS::__ANON__, avg 3µs/call | ||
| 46 | } | ||||
| 47 | } | ||||
| 48 | |||||
| - - | |||||
| 51 | 1; | ||||
| 52 | |||||
| 53 | __END__ | ||||
| 54 | |||||
| 55 | =pod | ||||
| 56 | |||||
| 57 | =encoding UTF-8 | ||||
| 58 | |||||
| 59 | =for :stopwords Florian Ragwitz Peter Rabbitson | ||||
| 60 | |||||
| 61 | =head1 NAME | ||||
| 62 | |||||
| 63 | B::Hooks::EndOfScope::XS - Execute code after a scope finished compilation - XS implementation | ||||
| 64 | |||||
| 65 | =head1 VERSION | ||||
| 66 | |||||
| 67 | version 0.13 | ||||
| 68 | |||||
| 69 | =head1 DESCRIPTION | ||||
| 70 | |||||
| 71 | This is the implementation of L<B::Hooks::EndOfScope> based on | ||||
| 72 | L<Variable::Magic>, which is an XS module dependent on a compiler. It will | ||||
| 73 | always be automatically preferred if L<Variable::Magic> is available. | ||||
| 74 | |||||
| 75 | =head1 FUNCTIONS | ||||
| 76 | |||||
| 77 | =head2 on_scope_end | ||||
| 78 | |||||
| 79 | on_scope_end { ... }; | ||||
| 80 | |||||
| 81 | on_scope_end $code; | ||||
| 82 | |||||
| 83 | Registers C<$code> to be executed after the surrounding scope has been | ||||
| 84 | compiled. | ||||
| 85 | |||||
| 86 | This is exported by default. See L<Sub::Exporter> on how to customize it. | ||||
| 87 | |||||
| 88 | =head1 AUTHORS | ||||
| 89 | |||||
| 90 | =over 4 | ||||
| 91 | |||||
| 92 | =item * | ||||
| 93 | |||||
| 94 | Florian Ragwitz <rafl@debian.org> | ||||
| 95 | |||||
| 96 | =item * | ||||
| 97 | |||||
| 98 | Peter Rabbitson <ribasushi@cpan.org> | ||||
| 99 | |||||
| 100 | =back | ||||
| 101 | |||||
| 102 | =head1 COPYRIGHT AND LICENSE | ||||
| 103 | |||||
| 104 | This software is copyright (c) 2008 by Florian Ragwitz. | ||||
| 105 | |||||
| 106 | This is free software; you can redistribute it and/or modify it under | ||||
| 107 | the same terms as the Perl 5 programming language system itself. | ||||
| 108 | |||||
| 109 | =cut |