App-GitHooks-Plugin-PerlCompile
    
    
  
  
  
view release on metacpan or search on metacpan
lib/App/GitHooks/Plugin/PerlCompile.pm view on Meta::CPAN
	# Ignore deleted files.
	return $PLUGIN_RETURN_SKIPPED
		if $git_action eq 'D';
	# Prepare extra libs specified in .githooksrc.
	my $lib_paths = $config->get( 'PerlCompile', 'lib_paths' );
	my @lib = map { ( '-I', $_ ) } split( /\s*,\s*/, $lib_paths // '' );
	# Execute perl -cw.
	my $path = File::Spec->catfile( $repository->work_tree(), $file );
	my ( $pid, $stdin, $stdout, $stderr ) = System::Command->spawn( $^X, '-cw', @lib, $path );
	# Retrieve the output.
	my $output;
	{
		local $/ = undef;
		$output = <$stderr>;
		chomp( $output );
	}
	# Raise an exception if we didn't get "syntax OK".
	die "$output\n"
		if $output !~ /\Q$file syntax OK\E$/x;
	return $PLUGIN_RETURN_PASSED;
}
				plugins                 => [ 'App::GitHooks::Plugin::PerlCompile' ],
			);
			# Set up test files.
			ok_add_files(
				files      => $test->{'files'},
				repository => $repository,
			);
			# Try to commit.
			my $stderr;
			lives_ok(
				sub
				{
					$stderr = Capture::Tiny::capture_stderr(
						sub
						{
							$repository->run( 'commit', '-m', 'Test message.' );
						}
					);
					note( $stderr );
				},
				'Commit the changes.',
			);
			like(
				$stderr,
				$test->{'expected'},
				"The output matches expected results.",
			);
		}
	);
}
( run in 0.569 second using v1.01-cache-2.11-cpan-c333fce770f )