Server IP : 127.0.0.2 / Your IP : 13.58.238.63 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/perl/5.22.1/autodie/ |
Upload File : |
package autodie::ScopeUtil; use strict; use warnings; # Docs say that perl 5.8.3 has Exporter 5.57 and autodie requires # 5.8.4, so this should "just work". use Exporter 5.57 qw(import); use autodie::Scope::GuardStack; our @EXPORT_OK = qw(on_end_of_compile_scope); # ABSTRACT: Utilities for managing %^H scopes our $VERSION = '2.26'; # VERSION # docs says we should pick __PACKAGE__ /<whatever> my $H_STACK_KEY = __PACKAGE__ . '/stack'; sub on_end_of_compile_scope { my ($hook) = @_; # Dark magic to have autodie work under 5.8 # Copied from namespace::clean, that copied it from # autobox, that found it on an ancient scroll written # in blood. # This magic bit causes %^H to be lexically scoped. $^H |= 0x020000; my $stack = $^H{$H_STACK_KEY}; if (not defined($stack)) { $stack = autodie::Scope::GuardStack->new; $^H{$H_STACK_KEY} = $stack; } $stack->push_hook($hook); return; } 1; =head1 NAME autodie::ScopeUtil - Utilities for managing %^H scopes =head1 SYNOPSIS use autodie::ScopeUtil qw(on_end_of_compile_scope); on_end_of_compile_scope(sub { print "Hallo world\n"; }); =head1 DESCRIPTION Utilities for abstracting away the underlying magic of (ab)using C<%^H> to call subs at the end of a (compile-time) scopes. Due to how C<%^H> works, these utilities are only useful during the compilation phase of a perl module and relies on the internals of how perl handles references in C<%^H>. This module is not a part of autodie's public API. =head2 Methods =head3 on_end_of_compile_scope on_end_of_compile_scope(sub { print "Hallo world\n"; }); Will invoke a sub at the end of a (compile-time) scope. The sub is called once with no arguments. Can be called multiple times (even in the same "compile-time" scope) to install multiple subs. Subs are called in a "first-in-last-out"-order (FILO or "stack"-order). =head1 AUTHOR Copyright 2013, Niels Thykier E<lt>niels@thykier.netE<gt> =head1 LICENSE This module is free software. You may distribute it under the same terms as Perl itself.