App-scriptdist

 view release on metacpan or  search on metacpan

lib/App/scriptdist.pm  view on Meta::CPAN


	use App::scriptdist qw(:all);

=head1 DESCRIPTION

This module provides the utility functions for the scriptdist program
that builds a basic Perl CPAN distribution around a standalone script
file that already exists.

I do not intend this for new development and don't want to create an
authoring tool. You can do that with some other tool (or fork this
one and build your own).

=head1 FUNCTIONS

=over 4

=item prompt( QUERY )

Provide a prompt, get the response, chomp the neewline, and return
the answer.

=cut

sub prompt {
	my( $query ) = shift;

	print $query;

	chomp( my $reply = <STDIN> );

	return $reply;
	}

=item find_files( DIRECTORY )

Find all the files under a directory.

=cut

sub find_files {
	my $directory = shift;

    my @files = ();

	my $wanted = sub {
		return unless -f $_;
		return if $_ =~ m<(?:CVS|\.svn|\.git)>;
		push @files, File::Spec->canonpath( $File::Find::name );
		};

    my %options = (
    	wanted => $wanted,
    	);

    find( \%options, $directory );

    return @files;
	}

=item copy( INPUT_FILE, OUTPUT_FILE, CONFIG_HASH )

Copy the file from one place to another.

=cut

sub copy {
	my( $input, $output, $hash ) = @_;

	print STDERR "Opening input [$input] for output [$output]\n";

	open my $in_fh,  '<', $input  or die "Could not open [$input]: $!\n";
	open my $out_fh, '>', $output or warn "Could not open [$output]: $!\n";

	my $count = 0;

	while( readline $in_fh ) {
		$count += s/%%SCRIPTDIST_(.*?)%%/$hash->{ lc $1 } || ''/gie;
		print {$out_fh} $_
		}

	print STDERR "Copied [$input] with $count replacements\n" unless $Quiet;
	}

=item gitify()

Unless the environment variable C<SCRIPTDIST_SKIP_GIT> is set, init
a git repo, add all the files, and make the initial commit.

=cut

sub gitify {
	return if $ENV{SCRIPTDIST_SKIP_GIT};
	chomp( my $git = `which git` );
	return unless length $git && -x $git;

	system $git, qw'init';
	system $git, qw'add .';
	system $git, qw'commit -a -m ', "Initial commit by $0 $VERSION";
	}

=item script_template( SCRIPT_NAME )

Return the script template.

=cut

sub script_template {
	my $script_name = shift;

	# Test::Pod thinks this stuff is pod if it's at the beginning
	# of the line
	my $script = <<"HERE";
	#!/usr/bin/perl

	=head1 NAME

	$script_name - this script does something

	=head1 SYNOPSIS



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