Apache-Logmonster
view release on metacpan or search on metacpan
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
alarm $p{timeout};
do {
print "(y/n): ";
$response = lc(<STDIN>);
chomp($response);
} until ( $response eq "n" || $response eq "y" );
alarm 0;
};
if ($@) {
$@ eq "alarm\n" ? print "timed out!\n" : carp;
}
return ($response && $response eq "y") ? 1 : 0;
}
do {
print "(y/n): ";
$response = lc(<STDIN>);
chomp($response);
} until ( $response eq "n" || $response eq "y" );
return ($response eq "y") ? 1 : 0;
}
1;
__END__
=head1 SYNOPSIS
use Apache::Logmonster::Utility;
my $toaster = Apache::Logmonster::Utility->new;
$util->file_write($file, lines=> @lines);
This is just one of the many handy little methods I have amassed here. Rather than try to remember all of the best ways to code certain functions and then attempt to remember them, I have consolidated years of experience and countless references from...
=head1 DESCRIPTION
This Apache::Logmonster::Utility package is my most frequently used one. Each method has its own documentation but in general, all methods accept as input a hashref with at least one required argument and a number of optional arguments.
=head1 DIAGNOSTICS
All methods set and return error codes (0 = fail, 1 = success) unless otherwise stated.
Unless otherwise mentioned, all methods accept two additional parameters:
debug - to print status and verbose error messages, set debug=>1.
fatal - die on errors. This is the default, set fatal=>0 to override.
=head1 DEPENDENCIES
Perl.
Scalar::Util - built-in as of perl 5.8
Almost nothing else. A few of the methods do require certian things, like extract_archive requires tar and file. But in general, this package (Apache::Logmonster::Utility) should run flawlessly on any UNIX-like system. Because I recycle this package ...
=head1 METHODS
=over
=item new
To use any of the methods below, you must first create a utility object. The methods can be accessed via the utility object.
############################################
# Usage : use Apache::Logmonster::Utility;
# : my $util = Apache::Logmonster::Utility->new;
# Purpose : create a new Apache::Logmonster::Utility object
# Returns : a bona fide object
# Parameters : none
############################################
=item ask
Get a response from the user. If the user responds, their response is returned. If not, then the default response is returned. If no default was supplied, 0 is returned.
############################################
# Usage : my $ask = $util->ask( "Would you like fries with that",
# default => "SuperSized!",
# timeout => 30
# );
# Purpose : prompt the user for information
#
# Returns : S - the users response (if not empty) or
# : S - the default ask or
# : S - an empty string
#
# Parameters
# Required : S - question - what to ask
# Optional : S - default - a default answer
# : I - timeout - how long to wait for a response
# Throws : no exceptions
# See Also : yes_or_no
=item extract_archive
Decompresses a variety of archive formats using your systems built in tools.
############### extract_archive ##################
# Usage : $util->extract_archive( 'example.tar.bz2' );
# Purpose : test the archiver, determine its contents, and then
# use the best available means to expand it.
# Returns : 0 - failure, 1 - success
# Parameters : S - archive - a bz2, gz, or tgz file to decompress
=item cwd_source_dir
Changes the current working directory to the supplied one. Creates it if it does not exist. Tries to create the directory using perl's builtin mkdir, then the system mkdir, and finally the system mkdir with sudo.
( run in 0.499 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )