Skip to content

Instantly share code, notes, and snippets.

@barefootcoder
Created October 28, 2011 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barefootcoder/1323605 to your computer and use it in GitHub Desktop.
Save barefootcoder/1323605 to your computer and use it in GitHub Desktop.
Demonstration of on_scope_end
package inner_pm;
BEGIN { warn "compiling inner pm" };
use B::Hooks::EndOfScope;
sub inner_pm_func
{
warn "entering inner pm sub";
unless (0)
{
on_scope_end sub { warn "on_scope_end hook called" };
}
warn "leaving inner pm sub";
}
warn "leaving inner pm compilation";
1;
#!/usr/bin/perl
BEGIN { warn "top of script" };
use test_on_scope_end;
BEGIN { warn "pm loaded" };
warn "normal runtime";
END { warn "in END block" };
BEGIN { warn "very end of compiling main script" };
package test_on_scope_end;
BEGIN { warn "compiling outer pm" };
use inner_pm;
BEGIN { warn "loaded inner pm" };
sub import
{
warn "entering import";
inner_pm::inner_pm_func();
}
warn "leaving outer pm compilation";
1;
@barefootcoder
Copy link
Author

Output:

[tyr:~/proj/method-signatures/gist] perl test_on_scope_end.pl
top of script at test_on_scope_end.pl line 3.
compiling outer pm at test_on_scope_end.pm line 3.
compiling inner pm at inner_pm.pm line 3.
leaving inner pm compilation at inner_pm.pm line 17.
loaded inner pm at test_on_scope_end.pm line 5.
leaving outer pm compilation at test_on_scope_end.pm line 13.
entering import at test_on_scope_end.pm line 9.
entering inner pm sub at inner_pm.pm line 9.
leaving inner pm sub at inner_pm.pm line 14.
pm loaded at test_on_scope_end.pl line 6.
very end of compiling main script at test_on_scope_end.pl line 11.
on_scope_end hook called at inner_pm.pm line 12.
normal runtime at test_on_scope_end.pl line 8.
in END block at test_on_scope_end.pl line 10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment