#!/usr/bin/perl use strict; use warnings; use ExtUtils::MakeMaker qw(prompt); use File::HomeDir; use Path::Class qw(file dir); use Template; use YAML; my $path = file(File::HomeDir->my_home, '/.pmsetuprc'); my $config = eval { YAML::LoadFile($path) } || {}; my $save; while (! $config->{author}) { $config->{author} = prompt("Your name: ", ''); $save++; } while (! $config->{email}) { $config->{email} = prompt("Your email: ", ''); $save++; } my $modname = shift @ARGV or die "Usage: $0 module\n"; $modname =~ s/-/::/g; write_plugin_files($modname, $config); END { YAML::DumpFile($path, $config) if $save; } sub write_plugin_files { my ($module, $config) = @_; # $module = "Foo::Bar" # $dist = "Foo-Bar" # $path = "Foo/Bar.pm" my @pkg = split /::/, $module; my $dist = join "-", @pkg; my $path = join("/", @pkg) . ".pm"; my $dir = dir($dist); $dir->subdir($_)->mkpath for qw( trunk tags branches ); chdir $dir->subdir('trunk'); my @template = YAML::Load(join '', ); my $vars = { module => $module, dist => $dist, path => $path, config => $config, localtime => scalar localtime }; for my $tmpl (@template) { my $file = $tmpl->{file}; $file =~ s/(\$\w+)/$1/eeg; write_file(file($file), $tmpl->{template}, $vars); } !system 'perl Makefile.PL' or die $?; !system 'make manifest' or die $?; !system 'make distclean' or die $?; } sub write_file { my ($path, $template, $vars) = @_; if (-e $path) { my $ans = prompt("$path exists. Override? [yN] ", 'n'); return if $ans !~ /[Yy]/; } my $dir = $path->dir; unless (-e $dir) { warn "Creating directory $dir\n"; $dir->mkpath; } my $tt = Template->new; $tt->process(\$template, $vars, \my $content); warn "Creating $path\n"; my $fh = $path->openw; $fh->print($content); $fh->close; } __DATA__ --- file: Makefile.PL template: | use inc::Module::Install; name '[% dist %]'; all_from 'lib/[% path %]'; # requires ''; # install_script ''; tests 't/*.t'; test_requires 'Test::More'; test_requires 'ok'; author_tests 'xt'; use_test_base; auto_include_deps; WriteAll; --- file: t/00_compile.t template: | use Test::More tests => 1; use ok '[% module %]'; --- file: xt/01_pod.t template: | use Test::More; eval "use Test::Pod 1.00"; plan skip_all => "Test::Pod 1.00 required for testing POD" if $@; all_pod_files_ok(); --- file: xt/02_podcoverage.t template: | use Test::More; eval "use Test::Pod::Coverage 1.04"; plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@; all_pod_coverage_ok(); --- file: xt/03_podspell.t template: | use Test::More; use Config (); use File::Spec (); eval "use Test::Spelling"; plan skip_all => "Test::Spelling is not installed." if $@; my $spell; for my $path (split /$Config::Config{path_sep}/ => $ENV{PATH}) { -x File::Spec->catfile($path => 'spell') and $spell = 'spell', last; -x File::Spec->catfile($path => 'ispell') and $spell = 'ispell -l', last; -x File::Spec->catfile($path => 'aspell') and $spell = 'aspell list', last; } plan skip_all => "spell/ispell/aspell are not installed." unless $spell; add_stopwords(map { split /[\s\:\-]/ } ); set_spell_cmd($spell) if $spell; local $ENV{LANG} = 'C'; all_pod_files_spelling_ok('lib'); __DATA__ [% config.author %] [% module %] --- file: xt/04_dependencies.t template: | use Test::More; eval "use Test::Dependencies exclude => ['[% module %]']"; plan skip_all => "Test::Dependencies required for testing dependencies" if $@; ok_dependencies(); --- file: Changes template: | Revision history for Perl extension [% module %] 0.01 - original version --- file: lib/$path template: | package [% module %]; use strict; use warnings; use 5.8.1; our $VERSION = '0.01'; 1; =head1 NAME [% module %] =head1 SYNOPSIS use [% module %]; =head1 DESCRIPTION [% module %] is =head1 AUTHOR [% config.author %] E[% config.email %]E =head1 LICENSE This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO =cut --- file: MANIFEST.SKIP template: | \bRCS\b \bCVS\b ^MANIFEST\. ^Makefile$ ~$ ^# \.old$ ^blib/ ^pm_to_blib ^MakeMaker-\d \.gz$ \.cvsignore ^t/9\d_.*\.t ^t/perlcritic \.svn/ \.shipit \._ \.DS_Store --- file: README template: | This is Perl module [% module %]. INSTALLATION [% module %] installation is straightforward. If your CPAN shell is set up, you should just be able to do % cpan [% module %] Download it, unpack it, then build it as per the usual: % perl Makefile.PL % make && make test Then install it: % make install DOCUMENTATION [% module %] documentation is available as in POD. So you can do: % perldoc [% module %] to read the documentation online with your favorite pager. [% config.author %] --- file: .shipit template: | steps = FindVersion, ChangeVersion, CheckChangeLog, Manifest, DistTest, Commit, Tag, MakeDist, UploadCPAN, DistClean svk.tagpattern = release-%v