App-Slaughter

 view release on metacpan or  search on metacpan

bin/slaughter  view on Meta::CPAN


=cut


use strict;
use warnings;

use English;
use Fcntl qw(:flock);
use File::Basename qw! basename !;
use File::Path qw! mkpath !;
use File::Spec;
use File::Temp qw! tempfile tempdir !;
use Getopt::Long;
use POSIX;
use Pod::Usage;



#
# The version of our release.
#
my $VERSION = '__UNRELEASED__';


#
#  Setup default options - include meta-data about the current host.
#
our %CONFIG = defaultOptions();


#
#  Parse configuration file.
#
parseConfigurationFile();


#
#  Parse command line, this takes precedence over the configuration file.
#
parseCommandLine();

#
#  If we're dumping, do that.
#
if ( $CONFIG{ 'dump' } )
{
    foreach my $var ( sort keys %CONFIG )
    {
        my $val = $CONFIG{ $var };
        $val = "undefined" if ( !defined($val) );

        print sprintf( "%-20s => %s", $var, $val ) . "\n";
    }
    exit;
}


#
#  At this point we should lock ourselves - we've parsed the command-line
# and we might have an updated lockfile - because this is the start of
# "real" work.
#
createLock();


#
#  Create a temporary directory, some transports need such a thing.
#
createTransportDir();


#
#  Ensure we're root, and ensure that we have the options setup that we need.
#
testEnvironment();

#
# Splay-time, if set.  The default is -1 == no delay.
#
if ( $CONFIG{ 'delay' } > 0 )
{
    my $rand = int( rand( $CONFIG{ 'delay' } ) );
    $CONFIG{ 'verbose' } &&
      print "Sleeping for $rand seconds - from max delay of $CONFIG{'delay'}\n";
    sleep($rand);
}


#
#  Attempt to load the policy from the remote source.
#
#
my ( $policy, $modules ) = loadPolicy();
if ( !$policy )
{
    print "Failed to fetch policy from server.\n";
    exit 0;
}



#
#  Write it out to disk, with the appropriate wrapper, such that it
#  becomes executable as valid perl.
#
my $file = writeoutPolicy( $policy, $modules );
$CONFIG{ 'verbose' } && print "Policy written to: $file\n";


#
#  Run the script locally, unless we're told not to.
#
if ( $CONFIG{ 'noexecute' } )
{
    $CONFIG{ 'verbose' } &&
      print "Not launching script due to --no-execute.\n";
}
else
{
    $CONFIG{ 'verbose' } &&



( run in 1.067 second using v1.01-cache-2.11-cpan-39bf76dae61 )