add support for assertions. Updated form of:
[p5sagit/p5-mst-13.2.git] / lib / assertions.pm
1 package assertions;
2
3 our $VERSION = '0.01';
4
5 # use strict;
6 # use warnings;
7
8 my $hint=0x01000000;
9
10 sub import {
11     shift;
12     @_=(scalar(caller)) unless @_;
13
14     if ($_[0] eq '&') {
15         return unless $^H & $hint;
16         shift;
17     }
18         
19     for my $tag (@_) {
20         unless (grep { $tag=~$_ } @{^ASSERTING}) {
21             $^H &= ~$hint;
22             return;
23         }
24     }
25     $^H |= $hint;
26 }
27
28 sub unimport {
29     $^H &= ~$hint;
30 }
31
32 1;
33 __END__
34
35
36 =head1 NAME
37
38 assertions - selects assertions
39
40 =head1 SYNOPSIS
41
42   sub assert (&) : assertion { &{$_[0]}() }
43
44   use assertions 'foo';
45   assert { print "asserting 'foo'\n" };
46
47   {
48       use assertions qw( foo bar );
49       assert { print "asserting 'foo' & 'bar'\n" };
50   }
51
52   {
53       use assertions qw( bar );
54       assert { print "asserting 'bar'\n" };
55   }
56
57   {
58       use assertions qw( & bar );
59       assert { print "asserting 'foo' & 'bar'\n" };
60   }
61
62   assert { print "asserting 'foo' again\n" };
63
64
65 =head1 ABSTRACT
66
67 C<assertions> pragma selects the tags used to control assertion
68 execution.
69
70 =head1 DESCRIPTION
71
72
73
74
75 =head2 EXPORT
76
77 None by default.
78
79 =head1 SEE ALSO
80
81
82
83 =head1 AUTHOR
84
85 Salvador Fandiño, E<lt>sfandino@yahoo.comE<gt>
86
87 =head1 COPYRIGHT AND LICENSE
88
89 Copyright 2002 by Salvador Fandiño
90
91 This library is free software; you can redistribute it and/or modify
92 it under the same terms as Perl itself.
93
94 =cut