1 package Module::Install::Catalyst;
6 require Module::Install::Base;
7 @ISA = qw/Module::Install::Base/;
11 use File::Copy::Recursive;
19 qw/Build Build.PL Changes MANIFEST META.yml Makefile.PL Makefile README
20 _build blib lib script t inc .*\.svn \.git _darcs \.bzr \.hg
21 debian build-stamp install-stamp configure-stamp/;
30 Module::Install::Catalyst - Module::Install extension for Catalyst
34 use inc::Module::Install;
37 all_from 'lib/MyApp.pm';
39 requires 'Catalyst::Runtime' => '5.7014';
41 catalyst_ignore('.*temp');
42 catalyst_ignore('.*tmp');
48 L<Module::Install> extension for Catalyst.
54 Calls L<catalyst_files> and L<catalyst_par>. Should be the last catalyst*
55 command called in C<Makefile.PL>.
62 if($Module::Install::AUTHOR) {
63 $self->include("File::Copy::Recursive");
67 *** Module::Install::Catalyst
69 $self->catalyst_files;
72 *** Module::Install::Catalyst finished.
78 Collect a list of all files a Catalyst application consists of and copy it
79 inside the blib/lib/ directory. Files and directories that match the modules
80 ignore list are excluded (see L<catalyst_ignore> and L<catalyst_ignore_all>).
91 CATFILES: for my $name ( readdir CATDIR ) {
92 for my $ignore (@IGNORE) {
93 next CATFILES if $name =~ /^$ignore$/;
94 next CATFILES if $name !~ /\w/;
99 my @path = split '-', $self->name;
100 for my $orig (@files) {
101 my $path = File::Spec->catdir( 'blib', 'lib', @path, $orig );
102 File::Copy::Recursive::rcopy( $orig, $path );
106 =head2 catalyst_ignore_all(\@ignore)
108 This function replaces the built-in default ignore list with the given list.
112 sub catalyst_ignore_all {
113 my ( $self, $ignore ) = @_;
117 =head2 catalyst_ignore(@ignore)
119 Add a regexp to the list of ignored patterns. Can be called multiple times.
123 sub catalyst_ignore {
124 my ( $self, @ignore ) = @_;
125 push @IGNORE, @ignore;
128 =head2 catalyst_par($name)
132 # Workaround for a namespace conflict
134 my ( $self, $par ) = @_;
138 my $name = $self->name;
141 my $class_string = join "', '", @CLASSES;
142 $class_string = "'$class_string'" if $class_string;
143 local $Data::Dumper::Indent = 0;
144 local $Data::Dumper::Terse = 1;
145 local $Data::Dumper::Pad = ' ';
146 my $paropts_string = Dumper(\%PAROPTS) || "{ }";
147 $self->postamble(<<EOF);
149 \t\$(NOECHO) \$(PERL) -Ilib -Minc::Module::Install -MModule::Install::Catalyst -e"Catalyst::Module::Install::_catalyst_par( '$par', '$name', { CLASSES => [$class_string], PAROPTS => $paropts_string, ENGINE => '$ENGINE', SCRIPT => '$SCRIPT', USAGE => q#$usage# } )"
152 Please run "make catalyst_par" to create the PAR package!
156 =head2 catalyst_par_core($core)
160 sub catalyst_par_core {
161 my ( $self, $core ) = @_;
162 $core ? ( $PAROPTS{'B'} = $core ) : $PAROPTS{'B'}++;
165 =head2 catalyst_par_classes(@clases)
169 sub catalyst_par_classes {
170 my ( $self, @classes ) = @_;
171 push @CLASSES, @classes;
174 =head2 catalyst_par_engine($engine)
178 sub catalyst_par_engine {
179 my ( $self, $engine ) = @_;
183 =head2 catalyst_par_multiarch($multiarch)
187 sub catalyst_par_multiarch {
188 my ( $self, $multiarch ) = @_;
189 $multiarch ? ( $PAROPTS{'m'} = $multiarch ) : $PAROPTS{'m'}++;
192 =head2 catalyst_par_options($optstring)
194 This command can be used in Makefile.PL to customise the PAR creation process.
195 The parameter "$optstring" contains a string with arguments in identical syntax
196 as arguments of B<pp> command from L<PAR::Packer> package.
200 # part of your Makefile.PL
202 catalyst_par_options("--verbose=2 -f Bleach -z 9");
203 # verbose mode; use filter 'Bleach'; zip with compression level 9
206 Note1: There is no reason to use catalyst_par_options() command multiple times
207 as you can spacify in "$optstring" as many options as you want. Still, it
208 is supported to call catalyst_par_options() more than once. In that case the
209 specified options are merged (collisions are handled on principle "later wins").
210 BEWARE: you are discouraged from using parameters -a -A -X -f -F -I -l -M in
211 multiple catalyst_par_options() as they are not merged but replaced as you would
214 Note2: By default the options "-x -p -o=<appname>.par" are set and option "-n"
215 is unset. This default always overrides whatever you specify by
216 catalyst_par_options().
220 sub catalyst_par_options {
221 my ( $self, $optstring ) = @_;
222 eval "use PAR::Packer ()";
224 warn "WARNING: catalyst_par_options ignored - you need PAR::Packer\n"
227 my $p = Getopt::Long::Parser->new(config => ['no_ignore_case']);
229 require Text::ParseWords;
231 local @ARGV = Text::ParseWords::shellwords($optstring);
232 $p->getoptions(\%o, PAR::Packer->options);
234 %PAROPTS = ( %PAROPTS, %o);
238 =head2 catalyst_par_script($script)
242 sub catalyst_par_script {
243 my ( $self, $script ) = @_;
247 =head2 catalyst_par_usage($usage)
251 sub catalyst_par_usage {
252 my ( $self, $usage ) = @_;
256 package Catalyst::Module::Install;
260 use File::Copy::Recursive 'rmove';
264 my ( $par, $class_name, $opts ) = @_;
266 my $ENGINE = $opts->{ENGINE};
267 my $CLASSES = $opts->{CLASSES} || [];
268 my $USAGE = $opts->{USAGE};
269 my $SCRIPT = $opts->{SCRIPT};
270 my $PAROPTS = $opts->{PAROPTS};
272 my $name = $class_name;
275 $par ||= "$name.par";
276 my $engine = $ENGINE || 'CGI';
280 die "Please install PAR\n" if $@;
281 eval "use PAR::Packer ()";
282 die "Please install PAR::Packer\n" if $@;
283 eval "use App::Packer::PAR ()";
284 die "Please install App::Packer::PAR\n" if $@;
285 eval "use Module::ScanDeps ()";
286 die "Please install Module::ScanDeps\n" if $@;
288 my $root = $FindBin::Bin;
289 $class_name =~ s/-/::/g;
290 my $path = File::Spec->catfile( 'blib', 'lib', split( '::', $class_name ) );
292 unless ( -f $path ) {
293 print qq/Not writing PAR, "$path" doesn't exist\n/;
296 print qq/Writing PAR "$par"\n/;
297 chdir File::Spec->catdir( $root, 'blib' );
299 my $par_pl = 'par.pl';
302 my $version = $Catalyst::VERSION;
303 my $class = $class_name;
306 $classes .= " require $_;\n" for @$CLASSES;
310 my $usage = $USAGE || <<"EOF";
312 [parl] $name\[.par] [script] [arguments]
315 parl $name.par $name\_server.pl -r
319 my $script = $SCRIPT;
320 my $tmp_file = IO::File->new("> $par_pl ");
321 print $tmp_file <<"EOF";
322 if ( \$ENV{PAR_PROGNAME} ) {
323 my \$zip = \$PAR::LibCache{\$ENV{PAR_PROGNAME}}
324 || Archive::Zip->new(__FILE__);
325 my \$script = '$script';
326 \$ARGV[0] ||= \$script if \$script;
327 if ( ( \@ARGV == 0 ) || ( \$ARGV[0] eq '-h' ) || ( \$ARGV[0] eq '-help' )) {
328 my \@members = \$zip->membersMatching('.*script/.*\.pl');
329 my \$list = " Available scripts:\\n";
330 for my \$member ( \@members ) {
331 my \$name = \$member->fileName;
332 \$name =~ /(\\w+\\.pl)\$/;
334 next if \$name =~ /^main\.pl\$/;
335 next if \$name =~ /^par\.pl\$/;
336 \$list .= " \$name\\n";
343 my \$file = shift \@ARGV;
344 \$file =~ s/^.*[\\/\\\\]//;
345 \$file =~ s/\\.[^.]*\$//i;
346 my \$member = eval { \$zip->memberNamed("./script/\$file.pl") };
347 die qq/Can't open perl script "\$file"\n/ unless \$member;
348 PAR::_run_member( \$member, 1 );
353 \$ENV{CATALYST_ENGINE} = '$engine';
356 require Catalyst::Helper;
357 require Catalyst::Test;
358 require Catalyst::Engine::HTTP;
359 require Catalyst::Engine::CGI;
360 require Catalyst::Controller;
361 require Catalyst::Model;
362 require Catalyst::View;
363 require Getopt::Long;
372 local $SIG{__WARN__} = sub { };
374 # STDERR used to be redirected to null, but this hid errors from PAR::Packer
377 # take user defined options first and override them with harcoded defaults
383 # do not replace the whole $opt{'a'} array; just push required default value
384 push @{$opt{'a'}}, grep( !/par.pl/, glob '.' );
386 App::Packer::PAR->new(
387 frontend => 'Module::ScanDeps',
388 backend => 'PAR::Packer',
396 rmove( File::Spec->catfile( 'blib', $par ), $par );
402 Catalyst Contributors, see Catalyst.pm
406 This library is free software. You can redistribute it and/or modify it under
407 the same terms as Perl itself.