root/misc/pmsetup

Revision 1919 (checked in by miyagawa, 14 years ago)

update pmsetup to use Module::Install

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use ExtUtils::MakeMaker qw(prompt);
5 use FileHandle;
6 use File::Copy;
7 use File::Path;
8 use File::Spec;
9 use YAML;
10
11 my $path   = File::Spec->catfile($ENV{HOME}, "/.pmsetuprc");
12 my $config = eval { YAML::LoadFile($path) } || {};
13
14 my $save;
15 while (! $config->{author}) {
16     $config->{author} = prompt("Your name: ", '');
17     $save++;
18 }
19
20 my $modname = shift @ARGV or die "Usage: $0 module\n";
21 my @pkg = split /::/, $modname;
22
23 mkdir_chdir(@pkg);
24 mk_makefile_pl($modname, @pkg);
25 my $libdir = mk_libdir_t_dir(@pkg);
26 mk_test_suite($modname);
27 mk_changes($modname);
28 mk_module_template($libdir, $modname, @pkg);
29 mk_manifest();
30 prepare_make();
31
32 END {
33     YAML::DumpFile($path, $config) if $save;
34 }
35
36 sub mkdir_chdir {
37     my @pkg = @_;
38     # mkdir Foo-Bar
39     my $moddir = join('-', @pkg);
40     mkdir $moddir, 0777;
41     chdir $moddir;
42 }
43
44 sub mk_makefile_pl {
45     my($modname, @pkg) = @_;
46
47     # Makefile.PL
48     my $dist = join('-', @pkg);
49     my $path = join('/', @pkg). '.pm';
50     my $mk = FileHandle->new('>Makefile.PL') or die $!;
51     $mk->print(<<MK);
52 use inc::Module::Install;
53 name('$dist');
54 all_from('lib/$path');
55
56 build_requires('Test::More');
57 auto_include;
58 WriteAll;
59 MK
60 }
61
62 sub mk_libdir_t_dir {
63     my @pkg = @_;
64
65     # lib/Foo/ & t/
66     my $libdir = 'lib/' . join '/', @pkg[0..$#pkg-1];
67     mkpath([ $libdir, 't' ], 1, 0777);
68     return $libdir;
69 }
70
71 sub mk_test_suite {
72     my $modname = shift;
73
74     # test suite
75     my $test = FileHandle->new(">t/00_compile.t") or die $!;
76     $test->print(<<TEST);
77 use strict;
78 use Test::More tests => 1;
79
80 BEGIN { use_ok '$modname' }
81 TEST
82     ;
83
84     $test = FileHandle->new(">t/99_pod.t") or die $!;
85     $test->print(<<'TEST');
86 use Test::More;
87 eval "use Test::Pod 1.00";
88 plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
89 all_pod_files_ok();
90 TEST
91     ;
92 }
93
94 sub mk_changes {
95     my $modname = shift;
96
97     my $localtime = localtime;
98     my $changes = FileHandle->new("> Changes") or die $!;
99     $changes->print(<<CHANGES);
100 Revision history for Perl extension $modname
101
102 0.01  $localtime
103         - original version
104 CHANGES
105     ;
106 }
107
108 sub mk_module_template {
109     my($libdir, $modname, @pkg) = @_;
110     my $module = FileHandle->new(">$libdir/$pkg[$#pkg].pm") or die $!;
111     $module->print(<<MODULE);
112 package $modname;
113
114 use strict;
115 use 5.8.0;
116 our \$VERSION = '0.01';
117
118 1;
119 __END__
120
121 =head1 NAME
122
123 $modname -
124
125 =head1 SYNOPSIS
126
127   use $modname;
128
129 =head1 DESCRIPTION
130
131 $modname is
132
133 =head1 AUTHOR
134
135 $config->{author}
136
137 =head1 LICENSE
138
139 This library is free software; you can redistribute it and/or modify
140 it under the same terms as Perl itself.
141
142 =head1 SEE ALSO
143
144 =cut
145 MODULE
146     ;
147 }
148
149 sub mk_manifest {
150     my $mani = FileHandle->new(">MANIFEST.SKIP") or die $!;
151     $mani->print(<<'MANI');
152 \bRCS\b
153 \bCVS\b
154 ^MANIFEST\.
155 ^Makefile$
156 ~$
157 \.old$
158 ^blib/
159 ^pm_to_blib
160 ^MakeMaker-\d
161 \.gz$
162 \.cvsignore
163 MANI
164     ;
165 }
166
167 sub prepare_make {
168     !system "perl Makefile.PL" or die $?;
169     !system 'make test' or die $?;
170     !system 'make manifest' or die $?;
171     !system 'make distclean' or die $?;
172 }
Note: See TracBrowser for help on using the browser.