Code Monkey home page Code Monkey logo

carp-assert's Introduction

NAME
    Carp::Assert - executable comments

SYNOPSIS
        # 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 Quayle

    Carp::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 Schwern <[email protected]>

WHAT 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 install

To 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

carp-assert's People

Contributors

dsteinbrunner avatar neilb avatar schwern avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

carp-assert's Issues

Warning: "Old package separator ' deprecated"

Getting the below warning importing Carp::Assert via Pithub:

/usr/bin/perlbrew \
  exec -q \
  --with blead \
  /home/regular/perl5/perlbrew/perls/blead/bin/perl5.37.9 \
  /home/regular/bin/pithub
Old package separator "'" deprecated at
  /home/regular/perl5/perlbrew/perls/blead/lib/site_perl/5.37.9/Carp/Assert.pm
  line 396.

Maybe it's time to start removing ' from shouldn't function in line 396:

sub shouldn't ($$) {     # emacs cperl-mode madness #' sub {
    my $env_ndebug = exists $ENV{PERL_NDEBUG} ? $ENV{PERL_NDEBUG}
                                              : $ENV{'NDEBUG'};
    if( $env_ndebug ) {
        return undef;
    }
    else {
        shouldnt($_[0], $_[1]);
    }
}

sub shouldn't ($$) { # emacs cperl-mode madness #' sub {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.