Devel::Hook

Mess around with BEGIN/CHECK/INIT/END blocks
Download

Devel::Hook Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Adriano Ferreira
  • Publisher web site:
  • http://search.cpan.org/~ferreira/

Devel::Hook Tags


Devel::Hook Description

Mess around with BEGIN/CHECK/INIT/END blocks Perl keeps arrays of subroutines that are executed at the beginning and at the end of a running Perl program and its program units. These subroutines correspond to the special code blocks: BEGIN, UNITCHECK, CHECK, INIT and END. (See details at "BEGIN, UNITCHECK, CHECK, INIT and END " in perlmod.) This module provides limited capabilities to manipulate these arrays.Such arrays belong to Perl's internals that you're not supposed to see. Entries in these arrays get consumed by the interpreter as it enters distinct compilation phases, triggered by statements like require, use, do, eval, etc. To play as safest as possible, the only allowed operations are to add entries to the start and to the end of these arrays. # add code hooks to the start of < BLOCK > array Devel::Hook->unshift_< BLOCK >_hook( @blocks ); # add code hooks to the end of < BLOCK > array Devel::Hook->push_< BLOCK >_hook( @blocks );where < BLOCK > is one of: BEGIN, UNITCHECK, CHECK, INIT or END.The hooks execute first if they are at the start of the array and last if they are at the end. Notice that the FIFO or LIFO nature of blocks according to their textual order of appearance at Perl source does not matter here. For example, BEGIN, UNITCHECK and INIT are FIFO (first-in, first-out) blocks while CHECK and END are LIFO (last-in, first-out). But the Perl interpreter and the user of this module inserts blocks at the start of arrays if they should execute earlier and at the end if they are to be executed later, with a homogeneous treatment with respect to the block arrays.SYNOPSIS use Devel::Hook (); INIT { print "INIT #2\n"; } BEGIN { Devel::Hook->push_INIT_hook( sub { print "INIT #3 (hook)\n" } ); Devel::Hook->unshift_INIT_hook( sub { print "INIT #1 (hook)\n" } ); } print "RUNTIME\n";Output will be: INIT #1 (hook) INIT #2 INIT #3 (hook) RUNTIME Requirements: · Perl


Devel::Hook Related Software