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->admin->copy_package(
64 'File::Copy::Recursive',
65 $INC{"File/Copy/Recursive.pm"},
70 *** Module::Install::Catalyst
72 $self->catalyst_files;
75 *** Module::Install::Catalyst finished.
81 Collect a list of all files a Catalyst application consists of and copy it
82 inside the blib/lib/ directory. Files and directories that match the modules
83 ignore list are excluded (see L<catalyst_ignore> and L<catalyst_ignore_all>).
94 CATFILES: for my $name ( readdir CATDIR ) {
95 for my $ignore (@IGNORE) {
96 next CATFILES if $name =~ /^$ignore$/;
97 next CATFILES if $name !~ /\w/;
102 my @path = split '-', $self->name;
103 for my $orig (@files) {
104 my $path = File::Spec->catdir( 'blib', 'lib', @path, $orig );
105 File::Copy::Recursive::rcopy( $orig, $path );
109 =head2 catalyst_ignore_all(\@ignore)
111 This function replaces the built-in default ignore list with the given list.
115 sub catalyst_ignore_all {
116 my ( $self, $ignore ) = @_;
120 =head2 catalyst_ignore(\@ignore)
122 Add a regexp to the list of ignored patterns. Can be called multiple times.
126 sub catalyst_ignore {
127 my ( $self, @ignore ) = @_;
128 push @IGNORE, @ignore;
131 =head2 catalyst_par($name)
135 # Workaround for a namespace conflict
137 my ( $self, $par ) = @_;
141 my $name = $self->name;
144 my $class_string = join "', '", @CLASSES;
145 $class_string = "'$class_string'" if $class_string;
146 local $Data::Dumper::Indent = 0;
147 local $Data::Dumper::Terse = 1;
148 local $Data::Dumper::Pad = ' ';
149 my $paropts_string = Dumper(\%PAROPTS) || "{ }";
150 $self->postamble(<<EOF);
152 \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# } )"
155 Please run "make catalyst_par" to create the PAR package!
159 =head2 catalyst_par_core($core)
163 sub catalyst_par_core {
164 my ( $self, $core ) = @_;
165 $core ? ( $PAROPTS{'B'} = $core ) : $PAROPTS{'B'}++;
168 =head2 catalyst_par_classes(@clases)
172 sub catalyst_par_classes {
173 my ( $self, @classes ) = @_;
174 push @CLASSES, @classes;
177 =head2 catalyst_par_engine($engine)
181 sub catalyst_par_engine {
182 my ( $self, $engine ) = @_;
186 =head2 catalyst_par_multiarch($multiarch)
190 sub catalyst_par_multiarch {
191 my ( $self, $multiarch ) = @_;
192 $multiarch ? ( $PAROPTS{'m'} = $multiarch ) : $PAROPTS{'m'}++;
195 =head2 catalyst_par_options($optstring)
197 This command can be used in Makefile.PL to customise the PAR creation process.
198 The parameter "$optstring" contains a string with arguments in identical syntax
199 as arguments of B<pp> command from L<PAR::Packer> package.
203 # part of your Makefile.PL
205 catalyst_par_options("--verbose=2 -f Bleach -z 9");
206 # verbose mode; use filter 'Bleach'; zip with compression level 9
209 Note1: There is no reason to use catalyst_par_options() command multiple times
210 as you can spacify in "$optstring" as many options as you want. Still, it
211 is supported to call catalyst_par_options() more than once. In that case the
212 specified options are merged (collisions are handled on principle "later wins").
213 BEWARE: you are discouraged from using parameters -a -A -X -f -F -I -l -M in
214 multiple catalyst_par_options() as they are not merged but replaced as you would
217 Note2: By default the options "-x -p -o=<appname>.par" are set and option "-n"
218 is unset. This default always overrides whatever you specify by
219 catalyst_par_options().
223 sub catalyst_par_options {
224 my ( $self, $optstring ) = @_;
225 eval "use PAR::Packer ()";
227 warn "WARNING: catalyst_par_options ignored - you need PAR::Packer\n"
230 my $p = Getopt::Long::Parser->new(config => ['no_ignore_case']);
232 require Text::ParseWords;
234 local @ARGV = Text::ParseWords::shellwords($optstring);
235 $p->getoptions(\%o, PAR::Packer->options);
237 %PAROPTS = ( %PAROPTS, %o);
241 =head2 catalyst_par_script($script)
245 sub catalyst_par_script {
246 my ( $self, $script ) = @_;
250 =head2 catalyst_par_usage($usage)
254 sub catalyst_par_usage {
255 my ( $self, $usage ) = @_;
259 package Catalyst::Module::Install;
263 use File::Copy::Recursive 'rmove';
267 my ( $par, $class_name, $opts ) = @_;
269 my $ENGINE = $opts->{ENGINE};
270 my $CLASSES = $opts->{CLASSES} || [];
271 my $USAGE = $opts->{USAGE};
272 my $SCRIPT = $opts->{SCRIPT};
273 my $PAROPTS = $opts->{PAROPTS};
275 my $name = $class_name;
278 $par ||= "$name.par";
279 my $engine = $ENGINE || 'CGI';
283 die "Please install PAR\n" if $@;
284 eval "use PAR::Packer ()";
285 die "Please install PAR::Packer\n" if $@;
286 eval "use App::Packer::PAR ()";
287 die "Please install App::Packer::PAR\n" if $@;
288 eval "use Module::ScanDeps ()";
289 die "Please install Module::ScanDeps\n" if $@;
291 my $root = $FindBin::Bin;
292 $class_name =~ s/-/::/g;
293 my $path = File::Spec->catfile( 'blib', 'lib', split( '::', $class_name ) );
295 unless ( -f $path ) {
296 print qq/Not writing PAR, "$path" doesn't exist\n/;
299 print qq/Writing PAR "$par"\n/;
300 chdir File::Spec->catdir( $root, 'blib' );
302 my $par_pl = 'par.pl';
305 my $version = $Catalyst::VERSION;
306 my $class = $class_name;
309 $classes .= " require $_;\n" for @$CLASSES;
313 my $usage = $USAGE || <<"EOF";
315 [parl] $name\[.par] [script] [arguments]
318 parl $name.par $name\_server.pl -r
322 my $script = $SCRIPT;
323 my $tmp_file = IO::File->new("> $par_pl ");
324 print $tmp_file <<"EOF";
325 if ( \$ENV{PAR_PROGNAME} ) {
326 my \$zip = \$PAR::LibCache{\$ENV{PAR_PROGNAME}}
327 || Archive::Zip->new(__FILE__);
328 my \$script = '$script';
329 \$ARGV[0] ||= \$script if \$script;
330 if ( ( \@ARGV == 0 ) || ( \$ARGV[0] eq '-h' ) || ( \$ARGV[0] eq '-help' )) {
331 my \@members = \$zip->membersMatching('.*script/.*\.pl');
332 my \$list = " Available scripts:\\n";
333 for my \$member ( \@members ) {
334 my \$name = \$member->fileName;
335 \$name =~ /(\\w+\\.pl)\$/;
337 next if \$name =~ /^main\.pl\$/;
338 next if \$name =~ /^par\.pl\$/;
339 \$list .= " \$name\\n";
346 my \$file = shift \@ARGV;
347 \$file =~ s/^.*[\\/\\\\]//;
348 \$file =~ s/\\.[^.]*\$//i;
349 my \$member = eval { \$zip->memberNamed("./script/\$file.pl") };
350 die qq/Can't open perl script "\$file"\n/ unless \$member;
351 PAR::_run_member( \$member, 1 );
356 \$ENV{CATALYST_ENGINE} = '$engine';
359 require Catalyst::Helper;
360 require Catalyst::Test;
361 require Catalyst::Engine::HTTP;
362 require Catalyst::Engine::CGI;
363 require Catalyst::Controller;
364 require Catalyst::Model;
365 require Catalyst::View;
366 require Getopt::Long;
375 local $SIG{__WARN__} = sub { };
376 open my $olderr, '>&STDERR';
377 open STDERR, '>', File::Spec->devnull;
380 # take user defined options first and override them with harcoded defaults
386 # do not replace the whole $opt{'a'} array; just push required default value
387 push @{$opt{'a'}}, grep( !/par.pl/, glob '.' );
389 App::Packer::PAR->new(
390 frontend => 'Module::ScanDeps',
391 backend => 'PAR::Packer',
397 open STDERR, '>&', $olderr;
401 rmove( File::Spec->catfile( 'blib', $par ), $par );
407 Catalyst Contributors, see Catalyst.pm
411 This library is free software. You can redistribute it and/or modify it under
412 the same terms as Perl itself.