Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schwern/carp-assert
Embedded sanity checks for Perl
https://github.com/schwern/carp-assert
Last synced: 3 months ago
JSON representation
Embedded sanity checks for Perl
- Host: GitHub
- URL: https://github.com/schwern/carp-assert
- Owner: schwern
- Created: 2010-01-02T23:59:00.000Z (about 15 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T14:09:04.000Z (almost 2 years ago)
- Last Synced: 2024-10-03T12:38:37.249Z (3 months ago)
- Language: Perl
- Homepage: http://search.cpan.org/dist/Carp-Assert
- Size: 50.8 KB
- Stars: 8
- Watchers: 6
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README
- Changelog: Changes
Awesome Lists containing this project
README
NAME
Carp::Assert - executable commentsSYNOPSIS
# Assertions are on.
use Carp::Assert;$next_sunrise_time = sunrise();
# Assert that the sun must rise in the next 24 hours.
assert(($next_sunrise_time - time) < 24*60*60) if DEBUG;# Assertions are off.
no Carp::Assert;$next_pres = divine_next_president();
# Assert that if you predict Dan Quayle will be the next president
# your crystal ball might need some polishing. However, since
# assertions are off, IT COULD HAPPEN!
shouldnt($next_pres, 'Dan Quayle') if DEBUG;DESCRIPTION
"We are ready for any unforseen event that may or may not
occur."
- Dan QuayleCarp::Assert is intended for a purpose like the ANSI C library assert.h.
If you're already familiar with assert.h, then you can probably skip
this and go straight to the FUNCTIONS section.Assertions are the explict expressions of your assumptions about the
reality your program is expected to deal with, and a declaration of
those which it is not. They are used to prevent your program from
blissfully processing garbage inputs (garbage in, garbage out becomes
garbage in, error out) and to tell you when you've produced garbage
output. (If I was going to be a cynic about Perl and the user nature,
I'd say there are no user inputs but garbage, and Perl produces nothing
but...)An assertion is used to prevent the impossible from being asked of your
code, or at least tell you when it does. For example:# Take the square root of a number.
sub my_sqrt {
my($num) = shift;# the square root of a negative number is imaginary.
assert($num >= 0);return sqrt $num;
}The assertion will warn you if a negative number was handed to your
subroutine, a reality the routine has no intention of dealing with.AUTHOR
Michael G SchwernWHAT IS THIS?
This is Carp::Assert, a perl module. Please see the README that comes with
this distribution.HOW DO I INSTALL IT?
To install this module, cd to the directory that contains this README
file and type the following:perl Makefile.PL
make test
make installTo install this module into a specific directory, do:
perl Makefile.PL PREFIX=/name/of/the/directory
...the rest is the same...Please also read the perlmodinstall man page, if available.
WHAT MODULES DO I NEED?
Carp