App-Midgen

 view release on metacpan or  search on metacpan

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

package App::Midgen::Role::Experimental;

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

use constant {THREE => 3,};

use Types::Standard qw( Bool );
use Moo::Role;
#requires qw( debug );

use Try::Tiny;
use Data::Printer {caller_info => 1,};
use Term::ANSIColor qw( :constants colored colorstrip );
use List::MoreUtils qw(firstidx);


#######
# composed method degree of separation
# parent A::B - child A::B::C
#######
sub degree_separation {
	my $self   = shift;
	my $parent = shift;
	my $child  = shift;

	# Use of implicit split to @_ is deprecated
	my $parent_score = @{[split /::/, $parent]};
	my $child_score  = @{[split /::/, $child]};
	warn 'parent - ' . $parent . ' score - ' . $parent_score if $self->debug;
	warn 'child - ' . $child . ' score - ' . $child_score    if $self->debug;

	# switch around for a positive number
	return $child_score - $parent_score;
}


#######
# remove_noisy_children
#######
sub remove_noisy_children {
	my $self = shift;
	my $required_ref = shift || return;
	my @sorted_modules;

	foreach my $module_name (sort keys %{$required_ref}) {
		push @sorted_modules, $module_name;
	}

	p @sorted_modules if $self->debug;

	foreach my $parent_name (@sorted_modules) {
		my $outer_index = firstidx { $_ eq $parent_name } @sorted_modules;

		# inc so we don't end up with parent eq child
		$outer_index++;
		foreach my $inner_index ($outer_index .. $#sorted_modules) {
			my $child_name = $sorted_modules[$inner_index];

			# we just caught an undef
			next if not defined $child_name;
			if ($child_name =~ /^ $parent_name ::/x) {

				my $valied_seperation = 1;

				# as we only do this against -x, why not be extra vigilant
				$valied_seperation = THREE
					if $parent_name =~ /^Dist::Zilla|Moose|MooseX|Moo|Mouse/;

				# Checking for one degree of separation
				# ie A::B -> A::B::C is ok but A::B::C::D is not
				if ($self->degree_separation($parent_name, $child_name)



( run in 2.595 seconds using v1.01-cache-2.11-cpan-d8267643d1d )