NAME
Devel::Assert - assertions for Perl >= 5.14
SYNOPSIS
use Devel::Assert; # release mode, won't perform checks
assert(3 > 2);
use Devel::Assert 'on';
assert(3 > 2); # oops, check your math
FEATURES
assert() call and all it's arguments are replaced with no-ops at compile time
not a source filter
DESCRIPTION
This module provides you with a C-like assert() function - it completely disappears when you don't want it. That's useful to force functions' contracts during development without sacrificing production performance.
That's just like tests, but inside your code.
sub get_url {
my ($self, $url, $cb) = @_;
assert length $url;
assert(ref($cb) eq 'CODE');
...
}
USAGE
use Devel::Assert; # import 'assert' function, but doesn't enable it
use Devel::Assert 'on'; # import 'assert' function and enable it
use Devel::Assert 'global'; # import 'assert' function and enable it in all later 'use Devel::Assert' imports
use Devel::Assert::Global; # the same, can be used as perl -MDevel::Assert::Global your_program.pl
DISABLING ASSERTIONS
To temporary disable assertions you can use the following two options:
no Devel::Assert;
# or
use Devel::Assert 'off';
But note that currently this feature is not lexically scoped. It disables checks right until the next 'use Devel::Assert' statement (whenever it happens). This may be quite counterintuitive.
CAVEATS
assert() calls in text evals do not respect compile-time mode for the current module, but rather take default mode - 'off', unless 'global' is in effect. If you want them 'on', import Devel::Assert with 'on' flag inside your eval'ed string.
SEE ALSO
assertions - for perls >= 5.9.0, different syntax (code attributes).
Carp::Assert - requires annoying 'if DEBUG' suffix.
AUTHOR
Sergey Aleynikov <randir@cpan.org>
COPYRIGHT
Copyright (C) 2009, 2015 Sergey Aleynikov
LICENSE
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.