<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package autodie;
use 5.008;
use strict;
use warnings;

use Fatal ();
our @ISA = qw(Fatal);
our $VERSION;

# ABSTRACT: Replace functions with ones that succeed or die with lexical scope

BEGIN {
    our $VERSION = '2.23'; # VERSION: Generated by DZP::OurPkg::Version
}

use constant ERROR_WRONG_FATAL =&gt; q{
Incorrect version of Fatal.pm loaded by autodie.

The autodie pragma uses an updated version of Fatal to do its
heavy lifting.  We seem to have loaded Fatal version %s, which is
probably the version that came with your version of Perl.  However
autodie needs version %s, which would have come bundled with
autodie.

You may be able to solve this problem by adding the following
line of code to your main program, before any use of Fatal or
autodie.

    use lib "%s";

};

# We have to check we've got the right version of Fatal before we
# try to compile the rest of our code, lest we use a constant
# that doesn't exist.

BEGIN {

    # If we have the wrong Fatal, then we've probably loaded the system
    # one, not our own.  Complain, and give a useful hint. ;)

    if ($Fatal::VERSION ne $VERSION) {
        my $autodie_path = $INC{'autodie.pm'};

        $autodie_path =~ s/autodie\.pm//;

        require Carp;

        Carp::croak sprintf(
            ERROR_WRONG_FATAL, $Fatal::VERSION, $VERSION, $autodie_path
        );
    }
}

# When passing args to Fatal we want to keep the first arg
# (our package) in place.  Hence the splice.

sub import {
        splice(@_,1,0,Fatal::LEXICAL_TAG);
        goto &amp;Fatal::import;
}

sub unimport {
        splice(@_,1,0,Fatal::LEXICAL_TAG);
        goto &amp;Fatal::unimport;
}

1;

__END__

=head1 NAME

autodie - Replace functions with ones that succeed or die with lexical scope

=head1 SYNOPSIS

    use autodie;            # Recommended: implies 'use autodie qw(:default)'

    use autodie qw(:all);   # Recommended more: defaults and system/exec.

    use autodie qw(open close);   # open/close succeed or die

    open(my $fh, "&lt;", $filename); # No need to check!

    {
        no autodie qw(open);          # open failures won't die
        open(my $fh, "&lt;", $filename); # Could fail silently!
        no autodie;                   # disable all autodies
    }

=head1 DESCRIPTION

        bIlujDI' yIchegh()Qo'; yIHegh()!

        It is better to die() than to return() in failure.

                -- Klingon programming proverb.

The C&lt;autodie&gt; pragma provides a convenient way to replace functions
that normally return false on failure with equivalents that throw
an exception on failure.

The C&lt;autodie&gt; pragma has I&lt;lexical scope&gt;, meaning that functions
and subroutines altered with C&lt;autodie&gt; will only change their behaviour
until the end of the enclosing block, file, or C&lt;eval&gt;.

If C&lt;system&gt; is specified as an argument to C&lt;autodie&gt;, then it
uses L&lt;IPC::System::Simple&gt; to do the heavy lifting.  See the
description of that module for more information.

=head1 EXCEPTIONS

Exceptions produced by the C&lt;autodie&gt; pragma are members of the
L&lt;autodie::exception&gt; class.  The preferred way to work with
these exceptions under Perl 5.10 is as follows:

    use feature qw(switch);

    eval {
        use autodie;

        open(my $fh, '&lt;', $some_file);

        my @records = &lt;$fh&gt;;

        # Do things with @records...

        close($fh);

    };

    given ($@) {
        when (undef)   { say "No error";                    }
        when ('open')  { say "Error from open";             }
        when (':io')   { say "Non-open, IO error.";         }
        when (':all')  { say "All other autodie errors."    }
        default        { say "Not an autodie error at all." }
    }

Under Perl 5.8, the C&lt;given/when&gt; structure is not available, so the
following structure may be used:

    eval {
        use autodie;

        open(my $fh, '&lt;', $some_file);

        my @records = &lt;$fh&gt;;

        # Do things with @records...

        close($fh);
    };

    if ($@ and $@-&gt;isa('autodie::exception')) {
        if ($@-&gt;matches('open')) { print "Error from open\n";   }
        if ($@-&gt;matches(':io' )) { print "Non-open, IO error."; }
    } elsif ($@) {
        # A non-autodie exception.
    }

See L&lt;autodie::exception&gt; for further information on interrogating
exceptions.

=head1 CATEGORIES

Autodie uses a simple set of categories to group together similar
built-ins.  Requesting a category type (starting with a colon) will
enable autodie for all built-ins beneath that category.  For example,
requesting C&lt;:file&gt; will enable autodie for C&lt;close&gt;, C&lt;fcntl&gt;,
C&lt;fileno&gt;, C&lt;open&gt; and C&lt;sysopen&gt;.

The categories are currently:

    :all
        :default
            :io
                read
                seek
                sysread
                sysseek
                syswrite
                :dbm
                    dbmclose
                    dbmopen
                :file
                    binmode
                    close
                    chmod
                    chown
                    fcntl
                    fileno
                    flock
                    ioctl
                    open
                    sysopen
                    truncate
                :filesys
                    chdir
                    closedir
                    opendir
                    link
                    mkdir
                    readlink
                    rename
                    rmdir
                    symlink
                    unlink
                :ipc
                    pipe
                    :msg
                        msgctl
                        msgget
                        msgrcv
                        msgsnd
                    :semaphore
                        semctl
                        semget
                        semop
                    :shm
                        shmctl
                        shmget
                        shmread
                :socket
                    accept
                    bind
                    connect
                    getsockopt
                    listen
                    recv
                    send
                    setsockopt
                    shutdown
                    socketpair
            :threads
                fork
        :system
            system
            exec


Note that while the above category system is presently a strict
hierarchy, this should not be assumed.

A plain C&lt;use autodie&gt; implies C&lt;use autodie qw(:default)&gt;.  Note that
C&lt;system&gt; and C&lt;exec&gt; are not enabled by default.  C&lt;system&gt; requires
the optional L&lt;IPC::System::Simple&gt; module to be installed, and enabling
C&lt;system&gt; or C&lt;exec&gt; will invalidate their exotic forms.  See L&lt;/BUGS&gt;
below for more details.

The syntax:

    use autodie qw(:1.994);

allows the C&lt;:default&gt; list from a particular version to be used.  This
provides the convenience of using the default methods, but the surety
that no behavioral changes will occur if the C&lt;autodie&gt; module is
upgraded.

C&lt;autodie&gt; can be enabled for all of Perl's built-ins, including
C&lt;system&gt; and C&lt;exec&gt; with:

    use autodie qw(:all);

=head1 FUNCTION SPECIFIC NOTES

=head2 print

The autodie pragma B&lt;&lt;does not check calls to C&lt;print&gt;&gt;&gt;.

=head2 flock

It is not considered an error for C&lt;flock&gt; to return false if it fails
due to an C&lt;EWOULDBLOCK&gt; (or equivalent) condition.  This means one can
still use the common convention of testing the return value of
C&lt;flock&gt; when called with the C&lt;LOCK_NB&gt; option:

    use autodie;

    if ( flock($fh, LOCK_EX | LOCK_NB) ) {
        # We have a lock
    }

Autodying C&lt;flock&gt; will generate an exception if C&lt;flock&gt; returns
false with any other error.

=head2 system/exec

The C&lt;system&gt; built-in is considered to have failed in the following
circumstances:

=over 4

=item *

The command does not start.

=item *

The command is killed by a signal.

=item *

The command returns a non-zero exit value (but see below).

=back

On success, the autodying form of C&lt;system&gt; returns the I&lt;exit value&gt;
rather than the contents of C&lt;$?&gt;.

Additional allowable exit values can be supplied as an optional first
argument to autodying C&lt;system&gt;:

    system( [ 0, 1, 2 ], $cmd, @args);  # 0,1,2 are good exit values

C&lt;autodie&gt; uses the L&lt;IPC::System::Simple&gt; module to change C&lt;system&gt;.
See its documentation for further information.

Applying C&lt;autodie&gt; to C&lt;system&gt; or C&lt;exec&gt; causes the exotic
forms C&lt;system { $cmd } @args &gt; or C&lt;exec { $cmd } @args&gt;
to be considered a syntax error until the end of the lexical scope.
If you really need to use the exotic form, you can call C&lt;CORE::system&gt;
or C&lt;CORE::exec&gt; instead, or use C&lt;no autodie qw(system exec)&gt; before
calling the exotic form.

=head1 GOTCHAS

Functions called in list context are assumed to have failed if they
return an empty list, or a list consisting only of a single undef
element.

=head1 DIAGNOSTICS

=over 4

=item :void cannot be used with lexical scope

The C&lt;:void&gt; option is supported in L&lt;Fatal&gt;, but not
C&lt;autodie&gt;.  To workaround this, C&lt;autodie&gt; may be explicitly disabled until
the end of the current block with C&lt;no autodie&gt;.
To disable autodie for only a single function (eg, open)
use C&lt;no autodie qw(open)&gt;.

C&lt;autodie&gt; performs no checking of called context to determine whether to throw
an exception; the explicitness of error handling with C&lt;autodie&gt; is a deliberate
feature.

=item No user hints defined for %s

You've insisted on hints for user-subroutines, either by pre-pending
a C&lt;!&gt; to the subroutine name itself, or earlier in the list of arguments
to C&lt;autodie&gt;.  However the subroutine in question does not have
any hints available.

=back

See also L&lt;Fatal/DIAGNOSTICS&gt;.

=head1 BUGS

"Used only once" warnings can be generated when C&lt;autodie&gt; or C&lt;Fatal&gt;
is used with package filehandles (eg, C&lt;FILE&gt;).  Scalar filehandles are
strongly recommended instead.

When using C&lt;autodie&gt; or C&lt;Fatal&gt; with user subroutines, the
declaration of those subroutines must appear before the first use of
C&lt;Fatal&gt; or C&lt;autodie&gt;, or have been exported from a module.
Attempting to use C&lt;Fatal&gt; or C&lt;autodie&gt; on other user subroutines will
result in a compile-time error.

Due to a bug in Perl, C&lt;autodie&gt; may "lose" any format which has the
same name as an autodying built-in or function.

C&lt;autodie&gt; may not work correctly if used inside a file with a
name that looks like a string eval, such as F&lt;eval (3)&gt;.

=head2 autodie and string eval

Due to the current implementation of C&lt;autodie&gt;, unexpected results
may be seen when used near or with the string version of eval.
I&lt;None of these bugs exist when using block eval&gt;.

Under Perl 5.8 only, C&lt;autodie&gt; I&lt;does not&gt; propagate into string C&lt;eval&gt;
statements, although it can be explicitly enabled inside a string
C&lt;eval&gt;.

Under Perl 5.10 only, using a string eval when C&lt;autodie&gt; is in
effect can cause the autodie behaviour to leak into the surrounding
scope.  This can be worked around by using a C&lt;no autodie&gt; at the
end of the scope to explicitly remove autodie's effects, or by
avoiding the use of string eval.

I&lt;None of these bugs exist when using block eval&gt;.  The use of
C&lt;autodie&gt; with block eval is considered good practice.

=head2 REPORTING BUGS

Please report bugs via the CPAN Request Tracker at
L&lt;http://rt.cpan.org/NoAuth/Bugs.html?Dist=autodie&gt;.

=head1 FEEDBACK

If you find this module useful, please consider rating it on the
CPAN Ratings service at
L&lt;http://cpanratings.perl.org/rate?distribution=autodie&gt; .

The module author loves to hear how C&lt;autodie&gt; has made your life
better (or worse).  Feedback can be sent to
E&lt;lt&gt;pjf@perltraining.com.auE&lt;gt&gt;.

=head1 AUTHOR

Copyright 2008-2009, Paul Fenwick E&lt;lt&gt;pjf@perltraining.com.auE&lt;gt&gt;

=head1 LICENSE

This module is free software.  You may distribute it under the
same terms as Perl itself.

=head1 SEE ALSO

L&lt;Fatal&gt;, L&lt;autodie::exception&gt;, L&lt;autodie::hints&gt;, L&lt;IPC::System::Simple&gt;

I&lt;Perl tips, autodie&gt; at
L&lt;http://perltraining.com.au/tips/2008-08-20.html&gt;

=head1 ACKNOWLEDGEMENTS

Mark Reed and Roland Giersig -- Klingon translators.

See the F&lt;AUTHORS&gt; file for full credits.  The latest version of this
file can be found at
L&lt;https://github.com/pjf/autodie/tree/master/AUTHORS&gt; .

=cut
</pre></body></html>