bleadperl adds a new kind of block, UNITCHECK. It is a new hook that runs after your code has been compiled. It fixes architectural issues with the hooks CHECK and INIT but avoids altering those and thus avoids causing problems for CHECK or INIT using code.

The following is an attempt to be get 5.10's UNITCHECK blocks to fall back to CHECK on less capable perls. This proof of concept works. There's also Check::UnitCheck which I'm sure works just fine. It might even be preferred but I wanted to see if I could get my same-syntax/pure-perl version working.

BEGIN { if ( $] < 5.009004 ) { my $src = <<'UNITCHECK'; print "Inventing UNITCHECK for $]\n"; require B; # This is a stub function. It exists just to capture the b +lock that will # follow it as a parameter. Magic will find this later and + call its argument. sub UNITCHECK (&) {} CHECK { # Read all the values in the main_cv's PADLIST. This p +robably doesn't work # for files that aren't the "main" script. for my $cv ( B::main_cv->PADLIST->ARRAY->ARRAY ) { # Find all anonymous subroutines. next unless $cv->isa( 'B::CV' ); # Hey! I'm missing the check to see that I'm in a +UNITCHECK block! # WTF!? Was the author on crack?! This is promiscu +ous as hell! # Call the anonymous function. my $sub = $cv->object_2svref; $sub->(); } } 1; UNITCHECK eval $src or die "$@\n$src"; } } UNITCHECK { print "Ok!\n"; }

⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊


In reply to A fail-over UNITCHECK for non-bleadperl by diotalevi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.