#!/usr/bin/env perl

use 5.010001;
use strict;
use warnings FATAL => 'all';

BEGIN {
	$PPI::XS_DISABLE = 1; # noise control - Prevent warning
}

our $VERSION = '0.12';
use English qw( -no_match_vars ); # Avoids reg-ex performance penalty
local $OUTPUT_AUTOFLUSH = 1;

use Data::Printer {
	caller_info => 1,
	colored     => 1,
};

# we are doing this so we can run from git during development
# perl ~/GitHub/App-Midgen/script/midgen -c
use FindBin qw($Bin);
use lib map {"$Bin/$_"} qw( lib ../lib );
use App::Midgen;

#######
# Start of Menu
#######
use Getopt::Long;
Getopt::Long::Configure('bundling');
use Pod::Usage;
my $help           = 0;
my $base_parent    = 0;    # 1 true ignore perl base functions
my $core           = 0;    # show perl core modules as well
my $verbose        = 0;    # option variable with default value (false)
my @output         = 'dsl';
my $mojo           = 0;    # show the Mojo detection
my $noisy_children = 0;    # unwanted noisy children
my $twins          = 0;    # unwanted twins
my $zero           = 0;    # display 0 instead of core
my $debug          = 0;    # lots of good stuff here :)
GetOptions(
	'verbose|v'        => \$verbose,
	'core|c'           => \$core,
	'base|parent|b|p'  => \$base_parent,
	'help|h|?'         => \$help,
	'mojo|m'           => \$mojo,
	'output|o=s'       => \@output,
	'twins|t'          => \$twins,
	'noisy_children|n' => \$noisy_children,
	'zero|z'           => \$zero,
	'debug|d'          => sub {
		$core           = 1;
		$verbose        = 1;
		$base_parent    = 1;
		$mojo           = 1;
		$noisy_children = 1;
		$twins          = 1;
		$debug          = 1;
	},
) or pod2usage(2);
pod2usage(1) if $help;

#######
# End of Menu
#######

say 'Running midgen v' . $VERSION;

my $midgen = App::Midgen->new(
	base_parent    => $base_parent,
	core           => $core,
	verbose        => $verbose,
	output_format  => $output[-1],
	mojo           => $mojo,
	noisy_children => $noisy_children,
	twins          => $twins,
	zero           => $zero,
	debug          => $debug,
);

p $midgen if $debug;

$midgen->run();

my $run_time = time - $BASETIME;
say 'I just spent ' . $run_time . 's doing all that for you';
say '__END__';

exit(0);

__END__

=pod

=encoding utf8

=head1 NAME

midgen - Check B<requires> & B<test_rerquires> of your package for CPAN inclusion.

=head1 VERSION

This document describes midgen version: 0.12

=head1 SYNOPSIS

Change to the root of your package and run

 midgen

Now with a Getopt --help or -?

 midgen -?

or

 midgen [options]

=head1 OPTIONS

=over 4

=item B<--help or -h>

Prints a help message and exits.

 Options:
   --help           brief help message
   --output         change format
   --core           show perl core modules
   --verbose        take a little peek as to what is going on
   --parent         show the base|parent includes as we find them
   --mojo           show the Mojo catch as we find them
   --noisy_children show them as we find them
   --twins          show twins as we find them
   --zero           show a 0 instead of core
   --debug          lot's of stuff very

=item B<--output or -o>

By default we output to STDOUT in 'dsl' format, 
so you can check, copy n paste or select an alternative format as shown below.

 midgen -o dsl		# Module::Include::DSL
 midgen -o mi		# Module::Include
 midgen -o build	# Build
 midgen -o dzil		# Dist::Zilla
 midgen -o dist		# dist.ini

=item B<--core or -c>

 * Shows modules that are in Perl core
 * some modules have a version number eg; constant, Carp
 * some have a version of 0 eg; strict, English
 * also show any recommends that we found

=item B<--verbose or -v>

Show filename that we are checking, as we go

=item B<--parent or -p>

alternative  --base or -b

Turn on extra output to show the base|parent modules, as we find them,
suggest you incorporate it with verbose for maximum affect

 midgen -vp

=item B<--mojo or -m>

Turn on extra output to show the /Mojo/ to Mojolicious catch, as we find them,
suggest you incorporate it with verbose for maximum affect

 midgen -vm

=item B<--noisy_children or -n>

Turn on extra output to show the modules considered to be noisy children, as we find them

 midgen -n

=item B<--twins or -t>

Turn on extra output to show the modules that are twins, as we find them, 
suggest you incorporate it with noisy_children for maximum affect

 midgen -nt
 
=item B<--zero or z>

Use a '0' instead of 'core' for core module version number, suggest you incorporate it with core for maximum affect


 midgen -cz

=item B<--debug or -d>

equivalent of -cnmptv and some :))

uses L<Data::Printer>

suggest you consider redirecting STDERR when the debug option is used

 midgen -d 2>debug.txt

=back

=head1 AUTHOR

See L<App::Midgen>

=head2 CONTRIBUTORS

See L<App::Midgen>

=head1 COPYRIGHT

See L<App::Midgen>

=head1 LICENSE

See L<App::Midgen>

=cut
