root/misc/pmsetup

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

add coremod and pmsetup

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