X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fassertions.pm;h=6c5c211b2750aa07649e124eb871c8a5d0f17689;hb=c1d8f74eb4326dca73e3ac3f73812dff8489ecf7;hp=0ced4bc228808a4c967aa7621584ac80707a6528;hpb=aefc56c5a86a8918fc9d52065e8cf4df301d4ee4;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/assertions.pm b/lib/assertions.pm index 0ced4bc..6c5c211 100644 --- a/lib/assertions.pm +++ b/lib/assertions.pm @@ -1,12 +1,12 @@ package assertions; -our $VERSION = '0.02'; +our $VERSION = '0.04'; # use strict; # use warnings; -my $hint=0x01000000; -my $seen_hint=0x02000000; +my $hint = 1; +my $seen_hint = 2; sub _syntax_error ($$) { my ($expr, $why)=@_; @@ -67,10 +67,10 @@ sub _calc_expr { shift @op; } elsif ($t eq '_') { - unless ($^H & $seen_hint) { + unless ($^H{assertions} & $seen_hint) { _carp "assertion status '_' referenced but not previously defined"; } - $t=($^H & $hint) ? 1 : 0; + $t=($^H{assertions} & $hint) ? 1 : 0; } elsif ($t ne '0' and $t ne '1') { $t = ( grep { ref $_ eq 'Regexp' @@ -109,44 +109,44 @@ sub import { foreach my $expr (@_) { unless (_calc_expr $expr) { # print STDERR "assertions deactived"; - $^H &= ~$hint; - $^H |= $seen_hint; + $^H{assertions} &= ~$hint; + $^H{assertions} |= $seen_hint; return; } } # print STDERR "assertions actived"; - $^H |= $hint|$seen_hint; + $^H{assertions} |= $hint|$seen_hint; } sub unimport { @_ > 1 and _carp($_[0]."->unimport arguments are being ignored"); - $^H &= ~$hint; + $^H{assertions} &= ~$hint; } sub enabled { if (@_) { if ($_[0]) { - $^H |= $hint; + $^H{assertions} |= $hint; } else { - $^H &= ~$hint; + $^H{assertions} &= ~$hint; } - $^H |= $seen_hint; + $^H{assertions} |= $seen_hint; } - return $^H & $hint ? 1 : 0; + return $^H{assertions} & $hint ? 1 : 0; } sub seen { if (@_) { if ($_[0]) { - $^H |= $seen_hint; + $^H{assertions} |= $seen_hint; } else { - $^H &= ~$seen_hint; + $^H{assertions} &= ~$seen_hint; } } - return $^H & $seen_hint ? 1 : 0; + return $^H{assertions} & $seen_hint ? 1 : 0; } 1; @@ -184,6 +184,10 @@ assertions - select assertions in blocks of code =head1 DESCRIPTION + *** WARNING: assertion support is only available from perl version + *** 5.9.0 and upwards. Check assertions::compat (also available from + *** this package) for an alternative backwards compatible module. + The C pragma specifies the tags used to enable and disable the execution of assertion subroutines.