App-Midgen

 view release on metacpan or  search on metacpan

lib/App/Midgen/Role/Output/MIdsl.pm  view on Meta::CPAN

package App::Midgen::Role::Output::MIdsl;

use constant {NONE => q{},};

use Moo::Role;
requires qw( no_index verbose );

# Load time and dependencies negate execution time
# use namespace::clean -except => 'meta';

our $VERSION = '0.34';
$VERSION = eval $VERSION;    ## no critic

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

use Term::ANSIColor qw( :constants colored );
use File::Spec;

#######
# header_dsl
#######
sub header_dsl {
	my $self         = shift;
	my $package_name = shift || NONE; # was shift // NONE -> defined $a ? $a : $b
	my $mi_ver       = shift || NONE; # defined shift ? shift : NONE - don't work as per perl5100delta.pod

	$package_name =~ s{::}{/}g;
	print "\nuse strict;\n";
	print "use warnings;\n";
	print "use inc::Module::Install::DSL "
		. colored($mi_ver, 'yellow') . ";\n";
	if ($package_name ne NONE) {
		print "all_from lib/$package_name.pm\n";
		print "requires_from lib/$package_name.pm\n";
	}

	print BRIGHT_BLACK . "license perl" . CLEAR . "\n";

	return;
}
#######
# body_dsl
#######
sub body_dsl {
	my $self         = shift;
	my $title        = shift;
	my $required_ref = shift || return;

	return if not %{$required_ref};

	print 'perl_version ' . $App::Midgen::Min_Version . "\n"
		if $title eq 'RuntimeRequires';
	print "\n";

	my $pm_length = 0;
	foreach my $module_name (sort keys %{$required_ref}) {
		if (length $module_name > $pm_length) {
			$pm_length = length $module_name;
		}
	}

	$title =~ s/^RuntimeRequires/requires/;
	$title =~ s/^TestRequires/test_requires/;

	foreach my $module_name (sort keys %{$required_ref}) {

		next
			if $title eq 'test_requires'
			&& $required_ref->{$module_name} =~ m/mcpan/;

		if ($module_name =~ /^Win32/sxm) {
			printf "%s %-*s %s %s\n", $title, $pm_length, $module_name,
				$required_ref->{$module_name}, colored('if win32', 'bright_green');
		}



( run in 1.953 second using v1.01-cache-2.11-cpan-f56aa216473 )