autodie

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

2.14      2013-02-22 15:43:33 Australia/Melbourne

        * FEATURE: Classes which claim they ->DOES('autodie::skip') are now
          skipped when generating exceptions.  This is mainly of use to
          utility classes. See `perldoc autodie::skip` for more details.
          (GH Issue #15)

        * FEATURE / BUGFIX / INCOMPAT: 'chmod' is now in the ':filesys'
          category (was in ':file').

        * BUGFIX: Added support for 'chown' and 'utime', that was
          previously overlooked. Mad props to RsrchBoy for spotting this.
          These are all in the ':filesys' category.
          (GH Pull #13)

        * BUGFIX: Added support for 'kill'. This is part of the
          ':ipc' category.

        * BUGFIX: Fixed bug whereby chmod, chown, kill, unlink and
          utime would not throw an exception when they didn't
          change all their files or signal all their processes.

        * TEST: truncate.t is now skipped on systems that don't have a
          working File::Temp.

        * TEST: open.t has a few more tests for exotic modes.

        * TEST: chown() tests are skipped on Win32, as chown on Windows
          is a no-op. (Thanks to Mithaldu for spotting this!)

        * TEST: Author tests now look for the AUTHOR_TESTING env
          variable (for dzil compliance).

        * TEST: Better testing for chown, chmod, and unlink.

        * TEST: Better testing for utime.

        * TEST: kwalitee.t is now only run when $ENV{RELEASE_TESTING} is set.

        * BUGFIX: Removed executable bits from some bundled text files.

        * BUILD: We now use dzil to manage autodie.

        * BUILD: Only Perl 5.8.4 and above is supported by autodie.

MANIFEST  view on Meta::CPAN

t/args.t
t/autodie.t
t/autodie_skippy.pm
t/autodie_test_module.pm
t/backcompat.t
t/basic_exceptions.t
t/binmode.t
t/blog_hints.t
t/caller.t
t/chmod.t
t/chown.t
t/context.t
t/context_lexical.t
t/core-trampoline-slurp.t
t/crickey.t
t/critic.t
t/dbmopen.t
t/eval_error.t
t/exception_class.t
t/exception_nonref.t
t/exceptions-smartmatch.t

lib/Fatal.pm  view on Meta::CPAN

# We have some tags that can be passed in for use with import.
# These are all assumed to be CORE::

my %TAGS = (
    ':io'      => [qw(:dbm :file :filesys :ipc :socket
                       read seek sysread syswrite sysseek )],
    ':dbm'     => [qw(dbmopen dbmclose)],
    ':file'    => [qw(open close flock sysopen fcntl binmode
                     ioctl truncate)],
    ':filesys' => [qw(opendir closedir chdir link unlink rename mkdir
                      symlink rmdir readlink chmod chown utime)],
    ':ipc'     => [qw(:msg :semaphore :shm pipe kill)],
    ':msg'     => [qw(msgctl msgget msgrcv msgsnd)],
    ':threads' => [qw(fork)],
    ':semaphore'=>[qw(semctl semget semop)],
    ':shm'     => [qw(shmctl shmget shmread)],
    ':system'  => [qw(system exec)],

    # Can we use qw(getpeername getsockname)? What do they do on failure?
    # TODO - Can socket return false?
    ':socket'  => [qw(accept bind connect getsockopt listen recv send

lib/Fatal.pm  view on Meta::CPAN


    # Our defaults don't include system(), because it depends upon
    # an optional module, and it breaks the exotic form.
    #
    # This *may* change in the future.  I'd love IPC::System::Simple
    # to be a dependency rather than a recommendation, and hence for
    # system() to be autodying by default.

    ':default' => [qw(:io :threads)],

    # Everything in v2.07 and before. This was :default less chmod and chown
    ':v207'    => [qw(:threads :dbm :socket read seek sysread
                   syswrite sysseek open close flock sysopen fcntl fileno
                   binmode ioctl truncate opendir closedir chdir link unlink
                   rename mkdir symlink rmdir readlink umask
                   :msg :semaphore :shm pipe)],

    # Chmod was added in 2.13
    ':v213'    => [qw(:v207 chmod)],

    # chown, utime, kill were added in 2.14
    ':v214'    => [qw(:v213 chown utime kill)],

    # umask was removed in 2.26
    ':v225' => [qw(:io :threads umask fileno)],

    # Version specific tags.  These allow someone to specify
    # use autodie qw(:1.994) and know exactly what they'll get.

    ':1.994' => [qw(:v207)],
    ':1.995' => [qw(:v207)],
    ':1.996' => [qw(:v207)],

lib/Fatal.pm  view on Meta::CPAN

    ':2.04'  => [qw(:v207)],
    ':2.05'  => [qw(:v207)],
    ':2.06'  => [qw(:v207)],
    ':2.06_01' => [qw(:v207)],
    ':2.07'  => [qw(:v207)],     # Last release without chmod
    ':2.08'  => [qw(:v213)],
    ':2.09'  => [qw(:v213)],
    ':2.10'  => [qw(:v213)],
    ':2.11'  => [qw(:v213)],
    ':2.12'  => [qw(:v213)],
    ':2.13'  => [qw(:v213)],     # Last release without chown
    ':2.14'  => [qw(:v225)],
    ':2.15'  => [qw(:v225)],
    ':2.16'  => [qw(:v225)],
    ':2.17'  => [qw(:v225)],
    ':2.18'  => [qw(:v225)],
    ':2.19'  => [qw(:v225)],
    ':2.20'  => [qw(:v225)],
    ':2.21'  => [qw(:v225)],
    ':2.22'  => [qw(:v225)],
    ':2.23'  => [qw(:v225)],

lib/Fatal.pm  view on Meta::CPAN

    CORE::sysseek
    CORE::umask
)} = ();

# Some functions can return true because they changed *some* things, but
# not all of them.  This is a list of offending functions, and how many
# items to subtract from @_ to determine the "success" value they return.

my %Returns_num_things_changed = (
    'CORE::chmod'  => 1,
    'CORE::chown'  => 2,
    'CORE::kill'   => 1,  # TODO: Could this return anything on negative args?
    'CORE::unlink' => 0,
    'CORE::utime'  => 2,
);

# Optional actions to take on the return value before returning it.

my %Retval_action = (
    "CORE::open"        => q{

lib/Fatal.pm  view on Meta::CPAN

    CORE::chdir
    CORE::link
    CORE::unlink
    CORE::rename
    CORE::mkdir
    CORE::symlink
    CORE::rmdir
    CORE::readlink
    CORE::umask
    CORE::chmod
    CORE::chown
    CORE::utime
    CORE::msgctl
    CORE::msgget
    CORE::msgrcv
    CORE::msgsnd
    CORE::semctl
    CORE::semget
    CORE::semop
    CORE::shmctl
    CORE::shmget

lib/Fatal.pm  view on Meta::CPAN

                $die;
            }

            return \$retval;
        ];
    }

    if (exists $Returns_num_things_changed{$call}) {

        # Some things return the number of things changed (like
        # chown, kill, chmod, etc). We only consider these successful
        # if *all* the things are changed.

        return qq[
            my \$num_things = \@_ - $Returns_num_things_changed{$call};
            my \$retval = $call(@argv);

            if (\$retval != \$num_things) {

                # We need \$context to throw an exception.
                # It's *always* set to scalar, because that's how
                # autodie calls chown() above.

                my \$context = "scalar";
                $die;
            }

            return \$retval;
        ];
    }

    # AFAIK everything that can be given an unopned filehandle

lib/autodie.pm  view on Meta::CPAN

                sysread
                sysseek
                syswrite
                :dbm
                    dbmclose
                    dbmopen
                :file
                    binmode
                    close
                    chmod
                    chown
                    fcntl
                    flock
                    ioctl
                    open
                    sysopen
                    truncate
                :filesys
                    chdir
                    closedir
                    opendir

lib/autodie/exception.pm  view on Meta::CPAN


    my $context = $E->context;

The context in which the subroutine was called by autodie; usually
the same as the context in which you called the autodying subroutine.
This can be 'list', 'scalar', or undefined (unknown).  It will never
be 'void', as C<autodie> always captures the return value in one way
or another.

For some core functions that always return a scalar value regardless
of their context (eg, C<chown>), this may be 'scalar', even if you
used a list context.

=cut

# TODO: The comments above say this can be undefined. Is that actually
# the case? (With 'system', perhaps?)

sub context     { return $_[0]->{$PACKAGE}{context} }

=head3 return

t/chmod.t  view on Meta::CPAN

isa_ok($@, 'autodie::exception', 'exception thrown for chmod');
like($@, SINGLE_DIGIT_ERROR_REGEXP, "Message should include numeric mode in octal form");

my ($fh, $filename) = tempfile;

eval { chmod(0755, $filename); };
ok(! $@, "We can chmod a file we own just fine.");

eval { chmod(0755, $filename, NO_SUCH_FILE) };
isa_ok($@, 'autodie::exception', 'chmod exception on any file failure.');
is($@->return,1,"Confirm autodie on a 'true' chown failure.");

t/chown.t  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;
use Test::More;
use constant NO_SUCH_FILE => "this_file_had_better_not_exist";
use autodie;
use File::Temp qw(tempfile);

if ($^O eq 'MSWin32') {
    plan skip_all => 'chown() seems to always succeed on Windows';
}

plan tests => 4;

eval {
    chown(1234, 1234, NO_SUCH_FILE);
};

isa_ok($@, 'autodie::exception', 'exception thrown for chown');

# Chown returns the number of files that we chowned. So really we
# should die if the return value is not equal to the number of arguments
# minus two.

my ($fh, $filename) = tempfile;

eval { chown($<, -1, $filename); };
ok(! $@, "Can chown a file we own just fine.");

eval { chown($<, -1, $filename, NO_SUCH_FILE); };
isa_ok($@, 'autodie::exception', "Exception if ANY file changemode fails");
is($@->return, 1, "Confirm we're dying on a 'true' chown failure.");

t/core-trampoline-slurp.t  view on Meta::CPAN

#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 3;

# Tests for GH #22
#
# Slurpy calls (like open, unlink, chown, etc) could not be
# interpreted properly if they leak into another file which
# doesn't have autodie enabled.

use autodie;
use FindBin qw($Bin);
use lib $Bin;
use autodie_test_module;

# This will throw an error, but it shouldn't throw a leak-guard
# failure.

t/version_tag.t  view on Meta::CPAN

    use autodie;

    chmod(0644,NO_SUCH_FILE);
};

isa_ok($@, 'autodie::exception', 'Our current version supports chmod');

eval {
    use autodie qw(:2.13);

    # 2.13 didn't support chown.  This shouldn't throw an
    # exception.

    chown(12345, 12345, NO_SUCH_FILE);
};

is($@,"","chown wasn't supported in 2.13");

SKIP: {

    if ($^O eq "MSWin32") { skip("chown() on Windows always succeeds.", 1) }

    eval {
        use autodie;

        chown(12345, 12345, NO_SUCH_FILE);
    };

    isa_ok($@, 'autodie::exception', 'Our current version supports chown');
}

# The patch in RT 46984 would have utime being set even if an
# older version of autodie semantics was requested. Let's see if
# it's coming from outside the eval context below.

eval { utime undef, undef, NO_SUCH_FILE; };
is($@,"","utime is not autodying outside of any autodie context.");

# Now do our regular versioning checks for utime.



( run in 1.893 second using v1.01-cache-2.11-cpan-5511b514fd6 )