Data-Tubes
view release on metacpan or search on metacpan
script/tubergen view on Meta::CPAN
#!/usr/bin/env perl
# vim: sts=3 ts=3 sw=3 et ai :
BEGIN {
local ($x, @ARGV, $/) = ('# __MOBUNDLE_INCLUSION__', __FILE__);
eval($mobundle = (<> =~ m{(^$x.*^$x)}ms)[0]);
}
use strict;
use warnings;
use 5.010;
my $VERSION = "0.740";
use Log::Log4perl::Tiny qw< :easy LOGLEVEL >;
use Data::Tubes qw< pipeline >;
########################################################################
#
# Input options and logger initialization
#
########################################################################
my %config = get_options(
['loglevel|log=s', default => 'INFO'],
# start putting your options here
['abstract|A=s', environment => 'TG_ABSTRACT', required => 1],
['author|a=s', environment => 'TG_AUTHOR', required => 1],
['email|e=s', environment => 'TG_EMAIL', required => 1],
['name|n=s', environment => 'TG_NAME', required => 1],
['output|o=s', environment => 'TG_OUTPUT'],
['year|y=s', environment => 'TG_YEAR',
default => 1900 + (localtime)[5]],
);
########################################################################
#
# Business Logic
#
########################################################################
$config{output} //= $config{name};
$config{modules_bundle} = $main::mobundle;
pipeline(
['Renderer::with_template_perlish', template => template()],
['Writer::to_files', filename => $config{output}],
{tap => 'sink'},
)->({structured => \%config});
my $mode = ((stat $config{output})[2] | 0111) & (~umask());
chmod $mode, $config{output};
########################################################################
#
# You should not need to fiddle any more beyond this point
#
########################################################################
# Ancillary scaffolding here
use Pod::Usage qw< pod2usage >;
use Getopt::Long qw< :config gnu_getopt >;
sub get_options {
my %config;
my @options = qw< usage! help! man! version! >;
my (%fallback_for, @required);
for my $option (@_) {
if (ref $option) {
script/tubergen view on Meta::CPAN
} ## end sub _rwtp_tp_t
sub render_with_template_perlish {
my %args = normalize_args(
@_,
[
{
%global_defaults,
start => '[%',
stop => '%]',
variables => {},
name => 'render with Template::Perlish',
},
'template'
]
);
my $name = $args{name};
$args{template_perlish} //= _create_tp(\%args);
my $tpi = defined $args{template_perlish_input};
my $ti = defined $args{template_input};
return
($tpi && $ti) ? _rwtp_tp_t(\%args)
: $tpi ? _rwtp_tp_nt(\%args)
: $ti ? _rwtp_ntp_t(\%args)
: _rwtp_ntp_nt(\%args);
} ## end sub render_with_template_perlish
shorter_sub_names(__PACKAGE__, 'render_');
1;
END_OF_FILE
# __MOBUNDLE_FILE__
);
unshift @INC, sub {
my ($me, $packfile) = @_;
return unless exists $file_for{$packfile};
(my $text = $file_for{$packfile}) =~ s/^\ //gmxs;
chop($text); # added \n at the end
open my $fh, '<', \$text or die "open(): $!\n";
return $fh;
}
unless $main::LOADED++;
} ## end BEGIN
# __MOBUNDLE_INCLUSION__
sub template {
my $template = <<'END_OF_TEMPLATE';
#!/usr/bin/env perl
# vim: sts=3 ts=3 sw=3 et ai :
### LEAVE THIS INITIAL SECTION AS-IS ##################################
BEGIN {
local ($x, @ARGV, $/) = ('# __MOBUNDLE_INCLUSION__', __FILE__);
eval((<> =~ m{(^$x.*^$x)}ms)[0]);
}
use strict;
use warnings;
use Pod::Usage qw< pod2usage >;
use Getopt::Long qw< :config gnu_getopt >;
use Data::Tubes qw< pipeline summon >;
### YOU CAN START CHANGING THINGS FROM HERE ON #########################
########################################################################
# __SECTION__
#
# Preamble
#
########################################################################
my $VERSION = '0.0.1';
use Log::Log4perl::Tiny qw< :easy LOGLEVEL :no_extra_logdie_message >;
use Template::Perlish qw< render >;
use Try::Tiny;
########################################################################
# __SECTION__
#
# Command Line Handling
#
########################################################################
my %config = get_options(
['loglevel|log=s', default => 'INFO'], # leave it or remove it
# start putting your options here
'foo|f=s',
['bar|b=s', default => 'default value for bar'],
['baz|B=i', required => 0, environment => 'MYAPP_BAZ'],
);
# Remove following line if you remove 'loglevel' in options above
LOGLEVEL($config{loglevel});
########################################################################
# __SECTION__
#
# Business Logic
#
########################################################################
# this is just an example to get you started, works with an input file
# like this:
#
# Flavio,44,salad
# FooBar,23,kiwi
my $template = <<'END_OF_TEMPLATE';
[[%%]% name %] is [[%%]% age %] and likes [[%%]% food %].
-----------------------------------------------------------
END_OF_TEMPLATE
pipeline(
'Source::iterate_files',
( run in 0.712 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )