9 my $seen_hint=0x02000000;
11 sub syntax_error ($$) {
14 Carp::croak("syntax error on assertion filter '$expr' ($why)");
20 if (warnings::enabled('assertions')) {
28 my @tokens=split / \s*
37 # print STDERR "tokens: -", join('-',@tokens), "-\n";
43 next if (!defined $t or $t eq '');
52 and syntax_error $expr, 'consecutive operators';
57 and syntax_error $expr, 'consecutive operators';
63 syntax_error $expr, 'unbalanced parens';
65 syntax_error $expr, "key missing after operator '$op[0]'";
71 unless ($^H & $seen_hint) {
72 my_warn "assertion status '_' referenced but not previously defined";
74 $t=($^H & $hint) ? 1 : 0;
76 elsif ($t ne '0' and $t ne '1') {
77 # print STDERR "'$t' resolved as ";
78 $t=grep ({ $t=~$_ } @{^ASSERTING}) ? 1 : 0;
79 # print STDERR "$t\n";
83 syntax_error $expr, 'operator expected';
85 if ($op[0] eq 'start') {
88 elsif ($op[0] eq '||') {
98 @now==1 or syntax_error $expr, 'unbalanced parens';
99 defined $op[0] and syntax_error $expr, "expression ends on operator '$op[0]'";
106 # print STDERR "\@_=", join("|", @_), "\n";
108 @_=(scalar(caller)) unless @_;
109 foreach my $expr (@_) {
110 unless (calc_expr $expr) {
111 # print STDERR "assertions deactived";
117 # print STDERR "assertions actived";
118 $^H |= $hint|$seen_hint;
134 assertions - selects assertions
138 sub assert (&) : assertion { &{$_[0]}() }
140 use assertions 'foo';
141 assert { print "asserting 'foo'\n" };
144 use assertions qw( foo bar );
145 assert { print "asserting 'foo' & 'bar'\n" };
149 use assertions qw( bar );
150 assert { print "asserting 'bar'\n" };
154 use assertions ' _ && bar ';
155 assert { print "asserting 'foo' && 'bar'\n" };
158 assert { print "asserting 'foo' again\n" };
163 C<assertions> pragma selects the tags used to control assertion
181 Salvador FandiE<ntilde>o, E<lt>sfandino@yahoo.comE<gt>
183 =head1 COPYRIGHT AND LICENSE
185 Copyright 2002 by Salvador FandiE<ntilde>o
187 This library is free software; you can redistribute it and/or modify
188 it under the same terms as Perl itself.