App-scriptdist
view release on metacpan or search on metacpan
lib/App/scriptdist.pm view on Meta::CPAN
#!/usr/bin/perl
use utf8;
use v5.10;
package App::scriptdist;
use strict;
use warnings;
use vars qw(
@EXPORT @EXPORT_OK %EXPORT_TAGS
%Content $VERSION
$Quiet
);
$VERSION = '1.006';
@EXPORT_OK = qw(
prompt find_files copy gitify content
script_template
%Content
);
%EXPORT_TAGS = (
'all' => [ @EXPORT_OK ],
);
$Quiet = 0;
use Exporter qw(import);
use Cwd;
use ExtUtils::Command;
use ExtUtils::Manifest;
use File::Basename qw(basename);
use File::Find qw(find);
use File::Spec;
use FindBin ();
=encoding utf8
=head1 NAME
App::scriptdist - create a distribution around a perl script
=head1 SYNOPSIS
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()
( run in 1.901 second using v1.01-cache-2.11-cpan-6aa56a78535 )