File: pptemplate

package info (click to toggle)
pdl 1%3A2.103-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,832 kB
  • sloc: perl: 22,701; ansic: 14,964; sh: 31; makefile: 30; sed: 6
file content (310 lines) | stat: -rwxr-xr-x 7,070 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#!perl

use strict;
use warnings;
use File::Basename;
use File::Path qw(make_path);

sub names {
  my ($module) = @_;
  my $pdname = 'lib/'.($module =~ s#::#/#gr) . '.pd';
  my $dir = $module =~ s#::#-#gr;
  return ($module, $pdname, $dir);
}

sub pdtmpl {
  my ($module) = @_;
  <<EOF =~ s/^!=/=/gmr;
# template auto generated by pptemplate
# uncomment commands, copy and fill in as needed
# see also the PDL::PP manpage

use strict;
use warnings;

our \$VERSION = '0.001';
pp_setversion(\$VERSION);

{ no warnings 'once'; # pass info back to Makefile.PL
#\$PDL::Core::Dev::EXTRAS{\$::PDLMOD}{OBJECT} .= join '', map " \$::PDLBASE/\$_\\$(OBJ_EXT)", qw(fftn);
#\$PDL::Core::Dev::EXTRAS{\$::PDLMOD}{DEFINE} .= qq{ -DFFT_FLOAT -DFFT_DOUBLE -DFFT_LDOUBLE};
#\$PDL::Core::Dev::EXTRAS{\$::PDLMOD}{INC} .= qq{ "-I\$::PDLBASE"};
}

# pp_bless('');       # package namespace of pp_def'ed functions
		      # defaults to 'PDL'

# pp_add_boot('');    # code to add to the XS boot section

# pp_addhdr('');      # add C code to the section preceding
		      # the first MODULE keyword

pp_addpm({At=>'Top'}, <<'EOPM');
use strict;
use warnings;

!=head1 NAME

$module - new PDL module to clutter up CPAN

!=head1 SYNOPSIS

  use $module;
  # FILL THIS IN

!=head1 DESCRIPTION

This will change the world.

!=cut
EOPM

# pp_add_exported(''); # add the list of functions
                       # to the list of exported functions

# pp_addxs('');        # add plain XS code to the XS section

# pp_add_isa(qw//);    # inheritance business: add arglist to modules \@ISA

pp_def('myinc',
  Pars => 'a(); [o]b()',
  Code => '\$b() = \$a() + 1;',
);

pp_done();  # you will need this to finish pp processing
EOF
}

sub pdMakefile {
  my ($module, $pdname) = @_;
  return <<EOM;
use strict;
use warnings;
use ExtUtils::MakeMaker;
use PDL::Core::Dev;

WriteMakefile(
  NAME                => '$module',
  AUTHOR              => 'A.U.Thor  <author\@example.com>',
  VERSION_FROM        => '$pdname',
  MIN_PERL_VERSION => '5.016',
  LICENSE=> 'perl',
  PREREQ_PM => {
    'PDL'  => '2.096', # deep mode
  },
  CONFIGURE_REQUIRES => {
    'PDL'  => '2.096',
  },
  BUILD_REQUIRES => {
    'PDL'  => '2.096',
  },
  TEST_REQUIRES => {
    'Test::More' => '0.88', # done_testing
    'Test::PDL' => '0.21',
  },
);

{
my \@pd_srcs;
package MY; # so that "SUPER" works right
sub init_PM {
  my (\$self) = \@_;
  \$self->SUPER::init_PM;
  \@pd_srcs = ::pdlpp_eumm_update_deep(\$self);
}
sub postamble { ::pdlpp_postamble(\@pd_srcs) }
}
EOM
}

sub pdManifest {
  my ($pdname) = @_;
  my $pd_dir = dirname $pdname;
  return <<"END_OF_MANIFEST";
$pdname
Makefile.PL
MANIFEST
MANIFEST.SKIP
t/basic.t
END_OF_MANIFEST
}

sub pdManifest_skip {
  my ($pdname,$dir) = @_;
  my $pd_dir    = dirname $pdname;
  my $bare_name = $pdname =~ s/\.pd$//r;
  return <<"SKIP_PROJECT" . <<'SKIP_GENERAL';
# This project's temporary files
^$bare_name(\\.(pm|xs|c)|-pp-)
$pd_dir/.*\\.(bs|o)\$
$dir-.*\\.tar\\.gz
SKIP_PROJECT

# Version control
^.git

# Avoid Makemaker generated and utility files
^Makefile$
\bMANIFEST\.bak
\bblib/
\bMakeMaker-\d
\bpm_to_blib\.ts$
\bpm_to_blib$
\bblibdirs\.ts$         # 6.18 through 6.25 generated this
^MYMETA

# Avoid temp and backup files.
~$
\.old$
\#$
\b\.#
\.bak$
\.swp$
SKIP_GENERAL
}

sub pdGitignore {
  my ($pdname,$dir) = @_;
  my $base_name = $pdname =~ s/\.pd$//r;
  return <<"GIT_PROJECT" . <<'GIT_GENERAL';
# This project's temporary files
$base_name.pm
*-pp-*.c
$base_name.bs
$base_name.c
$base_name.o
$base_name.xs
$dir-*.tar.gz
GIT_PROJECT

# ExtUtil::MakeMaker temporary files
/blib
/Makefile
/MANIFEST.bak
/Makefile.old
/MYMETA.*
/pm_to_blib
GIT_GENERAL
}

sub usage {
  require File::Basename;
  die "usage: @{[File::Basename::basename $0]} modulename\n";
}

usage if !@ARGV;
my ($module, $pdname, $dir) = names $ARGV[0];

die "$dir already exists; move out of the way if you want to proceed"
  if -d $dir;
mkdir $dir or die "$dir: $!";
chdir $dir or die "$dir: $!";

print "Setting up a template for '$module' in '$dir'\n";
my $pd_dir = dirname $pdname;
make_path $pd_dir; die "$pd_dir not created" if !-d $pd_dir;
open my $pdfl, ">", $pdname or die "$pdname: $!";
print $pdfl pdtmpl($module);
close $pdfl;

open my $mkfl, ">", 'Makefile.PL' or die "Makefile.PL: $!";
print $mkfl pdMakefile($module, $pdname);
close $mkfl;

open my $manifest, '>', 'MANIFEST'  or  die "MANIFEST: '$!'";
print $manifest pdManifest($pdname);
close $manifest;

open my $manifest_skip, '>', 'MANIFEST.SKIP'  or  die "MANIFEST.SKIP: '$!'";
print $manifest_skip pdManifest_skip($pdname,$dir);
close $manifest_skip;

open my $gitignore, '>', '.gitignore'  or  die ".gitignore: '$!'";
print $gitignore pdGitignore($pdname,$dir);
close $gitignore;

mkdir 't' or die "t: $!";
open my $tfl, '>', 't/basic.t' or die "t/basic.t: $!";
print $tfl <<EOF;
use strict;
use warnings;
use PDL::LiteF;
use Test::More;
use Test::PDL;
use $module;

is_pdl pdl(3,5)->myinc, pdl(4,6);

done_testing;
EOF
close $tfl;

=head1 NAME

pptemplate - script to generate Makefile.PL and PP file skeleton

=head1 SYNOPSIS

  # generate Makefile.PL and mymodule.pd in PDL-MyModule
  pptemplate PDL::MyModule;

=head1 DESCRIPTION

The B<pptemplate> script is the easiest way to start a new module
for PDL that contains PP code (see also L<PDL::PP>). The usage is simply

  pptemplate modulename;

As a result pptemplate will generate the usual directory structure you
would expect for a CPAN module: if you called C<pptemplate> as

  pptemplate PDL::CleverAlgs::Mymod;

Then you get the following files and directories:

  PDL-CleverAlgs-Mymod
  |-- lib
  |   |-- PDL
  |       |-- CleverAlgs
  |           |-- MyMod.pd
  |-- t
  |   |-- basic.t
  |-- Makefile.PL
  |   MANIFEST
  |   MANIFEST.SKIP
  |   .gitignore

Adapt F<MyMod.pd> to your needs and then you can build and test the
module as usual: From the directory F<PDL-CleverAlgs-Mymod>:

   $ perl Makefile.pl   # To create a Makefile
   $ make               # Build the module in blib
   $ make test          # Run the tests
   $ prove -vb          # ...or run the tests with prove

C<pptemplate> will stop if the directory to be created already exists,
to avoid accidents. Move it out of the way if you really want to scrap it.

The files F<MANIFEST>, F<MANIFEST.SKIP> and F<.gitignore> are for
bookkeeping: They avoid that temporary files created by building the
module end up in a git repository or a CPAN distribution.

As of 2.096, the "internal mode" of this script has been removed,
and it creates the files using the new "deep mode". This is because
the earlier practice of incorporating vast numbers of modules into
the main PDL distribution has been rethought due to the problems
it causes. Use this script to make it easy to create new CPAN-distributed
PDL modules.

=head1 BUGS

Feedback and bug reports are welcome.

=head1 COPYRIGHT

Copyright (c) 2001, Christian Soeller. All Rights Reserved.
This module is free software. It may be used, redistributed
and/or modified under the same terms as PDL itself
(see L<http://pdl.perl.org>).

=cut