App-Basis
view release on metacpan or search on metacpan
lib/App/Basis.pm view on Meta::CPAN
# preserve code blocks
$txt =~ s{(`{2,})(.+?)(?<!`)\1(?!`)}
{$1.($code{$2}=md5_base64($2)).$1}egs ;
# preserve inline blocks too
$txt =~ s{(`)(.+?)\1}{$1.($code{$2}=md5_base64($2)).$1}egm ;
# converter everything else
$txt = _horizontal($txt) ;
$txt = _header($txt) ;
$txt = _bold_underline_strike($txt) ;
$txt = _list($txt) ;
$txt = _quote($txt) ;
$txt = _color($txt) ;
# put back inline blocks
$txt =~ s{(`)(.+?)\1}{$1._get_source($2,\%code).$1}egm ;
# put back code blocks too
$txt =~ s{(`{3})(.+?)(?<!`)\1(?!`)}
{$1._get_source($2,\%code).$1}egs ;
say $txt;
}
# ----------------------------------------------------------------------------
# make sure we do any cleanup required
END {
# call any user supplied cleanup
if ($_app_simple_cleanup_func) {
$_app_simple_cleanup_func->() ;
$_app_simple_cleanup_func = undef ;
}
}
# ----------------------------------------------------------------------------
1 ;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::Basis - Simple way to create applications
=head1 VERSION
version 1.2
=head1 SYNOPSIS
use 5.10.0 ;
use strict ;
use warnings ;
use POSIX qw(strftime) ;
use App::Basis
sub ctrlc_func {
# code to decide what to do when CTRL-C is pressed
}
sub cleanup_func {
# optionally clean up things when the script ends
}
sub debug_func {
my ($lvl, $debug) = @_;
if(!$debug) {
$debug = $lvl ;
# set a default level
$lvl = 'INFO' ;
}
say STDERR strftime( '%Y-%m-%d %H:%M:%S', gmtime( time() ) ) . " [$lvl] " . get_program() . " " . $debug;
}
# main
my %opt = App::Basis::init_app(
help_text => 'Sample program description'
, help_cmdline => 'extra stuff to print about command line use'
, options => {
'file|f=s' => {
desc => 'local system location of xml data'
, required => 1
}
, 'url|u=s' => {
desc => 'where to find xml data on the internet'
, validate => sub { my $url = shift ; return $url =~ m{^(http|file|ftp)://} ; }
}
, 'keep|k' => {
# no point in having this if there is no file option
desc => 'keep the local file, do not rename it'
, depends => 'file'
}
, 'counter|c=i' => {
desc => 'check a counter'
, default => 5
}
, 'basic' => 'basic argument, needs no hashref data'
}
, ctrl_c => \&ctrl_c_handler # override built in ctrl-c handler
, cleanup => \&cleanup_func # optional func to call to clean up
, debug => \&debug_func # optional func to call with debugging data
, 'verbose|v' => 'be verbose about things',
, log_file => "~/log/fred.log" # alternative place to store default log messages
) ;
show_usage("need keep option") if( !$opt{keep}) ;
msg_exit( "spurious reason to exit with error code 3", 3) ;
=head1 DESCRIPTION
There are a number of ways to help script development and to encorage people to do the right thing.
One of thses is to make it easy to get parameters from the command line. Obviously you can play with Getopt::Long and
continuously write the same code and add in your own handlers for help etc, but then your co-workers and friends
make not be so consistent, leading to scripts that have no help and take lots of cryptic parameters.
So I created this module to help with command line arguments and displaying help, then I added L<App::Basis::Config> because
( run in 2.825 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )