Dist-Build

 view release on metacpan or  search on metacpan

lib/Dist/Build/Core.pm  view on Meta::CPAN

		my $pattern = $planner->create_pattern(dir => $dir, file => '*.PL');
		$planner->create_subst(
			on    => $pattern,
			subst => sub {
				my ($source) = @_;
				(my $target = $source) =~ s/\.PL\z//;
				$planner->create_node(
					target       => $target,
					dependencies => [ $source ],
					actions      => [
						command(get_perl(%args), $source, $target),
					],
				);
			},
		);
	});

	$planner->add_delegate('autoclean', sub {
		my ($planner) = @_;
		my @targets = grep { !/^blib\b/ } map { $_->target } grep { ! $_->phony } $planner->materialize->nodes;

		my $clean_action = function(
			function  => 'remove_tree',
			module    => 'File::Path',
			arguments => [ 'blib', @targets ],
			exports   => 'explicit',
			message   => "rm_r @targets",
		);
		$planner->create_node(
			target       => 'clean',
			phony        => 1,
			actions      => [ $clean_action ],
		);

		my @real_targets = qw/Build _build MYMETA.json MYMETA.yml/;
		my $realclean_action = function(
			function  => 'remove_tree',
			module    => 'File::Path',
			arguments => \@real_targets,
			exports   => 'explicit',
			message   => "rm_r @real_targets",
		);
		$planner->create_node(
			target       => 'realclean',
			phony        => 1,
			dependencies => [ 'clean' ],
			actions      => [ $realclean_action ],
		);
	});
}

sub copy {
	my ($source, $target, %options) = @_;

	make_path(dirname($target));
	unlink $target if -f $target;
	File::Copy::copy($source, $target) or croak "Could not copy: $!";

	my ($atime, $mtime) = (stat $source)[8,9];
	utime $atime, $mtime, $target;
	chmod 0444 & ~umask, $target;

	return;
}

sub manify {
	my ($input_file, $output_file, $section) = @_;
	require Pod::Man;
	Pod::Man->new(section => $section)->parse_from_file($input_file, $output_file);
	return;
}

my @default_libs = map { catdir('blib', $_) } qw/arch lib/;

sub tap_harness {
	my (%args) = @_;
	my @test_files;
	if ($args{test_files}) {
		@test_files = @{ delete $args{test_files} };
	} else {
		my $dir = delete $args{test_dir} // 't';
		@test_files = sort +find(qr/\.t$/, $dir);
	}
	my @libs = $args{libs} ? @{ $args{libs} } : @default_libs;
	my %test_args = (
		(color => 1) x !!-t STDOUT,
		%args,
		lib => [ map { rel2abs($_) } @libs ],
	);
	$test_args{verbosity} = delete $test_args{verbose} if exists $test_args{verbose};
	require TAP::Harness::Env;
	my $tester  = TAP::Harness::Env->create(\%test_args);
	my $results = $tester->runtests(@test_files);
	croak "Errors in testing.  Cannot continue.\n" if $results->has_errors;
}

sub install {
	my (%args) = @_;
	ExtUtils::Install::install($args{install_map}, $args{verbose}, $args{dry_run}, $args{uninst});
	return;
}

sub dump_binary {
	my ($filename, $content) = @_;
	open my $fh, '>:raw', $filename;
	print $fh $content;
}

sub dump_text {
	my ($filename, $content, $encoding) = @_;
	open my $fh, ">:encoding($encoding)", $filename;
	print $fh $content;
}

my $json_backend = Parse::CPAN::Meta->json_backend;
my $json = $json_backend->new->canonical->pretty->utf8;

sub dump_json {
	my ($filename, $content) = @_;
	open my $fh, '>:raw', $filename;
	print $fh $json->encode($content);



( run in 0.780 second using v1.01-cache-2.11-cpan-39bf76dae61 )