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) {
         my ($spec, %opts) = @$option;
         push @options, $spec;

         my ($name) = split /\|/, $spec, 2;
         if (exists $opts{default}) {
            $config{$name} = $opts{default};
         }
         if (exists $opts{environment}) {
            $config{$name} = $ENV{$opts{environment}}
               if defined $ENV{$opts{environment}};
         }
         if (exists $opts{fallback}) {
            $fallback_for{$name} = $opts{fallback};
         }
         if (exists $opts{required}) {
            push @required, $name;
         }
      } ## end if (ref $option)
      else {
         push @options, $option;
      }
   } ## end for my $option (@_)

   GetOptions(\%config, @options)
     or pod2usage(-verbose => 99, -sections => 'USAGE');
   pod2usage(message => "$0 $VERSION", -verbose => 99,
      -sections => ' ') if $config{version};
   pod2usage(-verbose => 99, -sections => 'USAGE') if $config{usage};
   pod2usage(-verbose => 99, -sections => 'USAGE|EXAMPLES|OPTIONS')
     if $config{help};
   pod2usage(-verbose => 2) if $config{man};

   while (my ($key, $value) = each %fallback_for) {
      next if exists $config{$key};
      $config{$key} = $value;
   }

   my @missing = grep { ! exists $config{$_} } @required;
   pod2usage(message => "missing options @missing",
      -verbose => 99, -sections => 'USAGE')
     if @missing;

   return %config if wantarray();



( run in 0.537 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )