Hello rootcho,
I hadn’t used the assertions module before, but playing around with it, in light of the advice in the 2007 thread how to use attributes?, I came up with this:
#! perl use strict; use warnings; use Attribute::Handlers; sub assertion : ATTR{'CODE'}; no warnings; sub assert(&) : assertion { &{$_[0]}() } use warnings; use assertions 'foo'; assert { print "asserting 'foo'\n" }; { use assertions qw( foo bar ); assert { print "asserting 'foo' and 'bar'\n" }; } { use assertions qw( bar ); assert { print "asserting only 'bar'\n" }; } { use assertions '_ && bar'; assert { print "asserting 'foo' && 'bar'\n" }; } assert { print "asserting 'foo' again\n" };
Output:
22:14 >perl 783_SoPW.pl asserting 'foo' asserting 'foo' and 'bar' asserting only 'bar' asserting 'foo' && 'bar' asserting 'foo' again 22:17 >
Whether the optimisation also works as desired, I haven’t tested, but this should at least give you a basis for further experimentation.
Hope it helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: assertions ? how do they work..
by Athanasius
in thread assertions ? how do they work..
by rootcho
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |