C::Devel - new branche catalyst_par_options (push more options into PAR creation...
[catagits/Catalyst-Devel.git] / lib / Module / Install / Catalyst.pm
index 0148baf..fc9b61d 100644 (file)
@@ -10,26 +10,38 @@ use File::Find;
 use FindBin;
 use File::Copy::Recursive 'rcopy';
 use File::Spec ();
+use Getopt::Long;
+use Data::Dumper;
 
 my $SAFETY = 0;
 
 our @IGNORE =
   qw/Build Build.PL Changes MANIFEST META.yml Makefile.PL Makefile README
-  _build blib lib script t inc \.svn \.git _darcs \.bzr \.hg/;
+  _build blib lib script t inc .*\.svn \.git _darcs \.bzr \.hg
+  debian build-stamp install-stamp configure-stamp/;
 our @CLASSES   = ();
 our $ENGINE    = 'CGI';
-our $CORE      = 0;
-our $MULTIARCH = 0;
-our $SCRIPT;
-our $USAGE;
+our $SCRIPT    = '';
+our $USAGE     = '';
+our %PAROPTS   = ();
 
 =head1 NAME
 
-Module::Install::Catalyst - Module::Install extension for Catalyst
-
+  Module::Install::Catalyst - Module::Install extension for Catalyst
+  
 =head1 SYNOPSIS
-
-See L<Catalyst>
+  
+  use inc::Module::Install;
+  
+  name 'MyApp';
+  all_from 'lib/MyApp.pm';
+  
+  requires 'Catalyst::Runtime' => '5.7014';
+  
+  catalyst_ignore('.*temp');
+  catalyst_ignore('.*tmp');
+  catalyst;
+  WriteAll;
 
 =head1 DESCRIPTION
 
@@ -39,6 +51,9 @@ L<Module::Install> extension for Catalyst.
 
 =head2 catalyst
 
+Calls L<catalyst_files> and L<catalyst_par>. Should be the last catalyst*
+command called in C<Makefile.PL>.
+
 =cut
 
 sub catalyst {
@@ -55,6 +70,10 @@ EOF
 
 =head2 catalyst_files
 
+Collect a list of all files a Catalyst application consists of and copy it  
+inside the blib/lib/ directory. Files and directories that match the modules 
+ignore list are excluded (see L<catalyst_ignore> and L<catalyst_ignore_all>).
+
 =cut
 
 sub catalyst_files {
@@ -81,6 +100,8 @@ sub catalyst_files {
 
 =head2 catalyst_ignore_all(\@ignore)
 
+This function replaces the built-in default ignore list with the given list.
+
 =cut
 
 sub catalyst_ignore_all {
@@ -90,6 +111,8 @@ sub catalyst_ignore_all {
 
 =head2 catalyst_ignore(\@ignore)
 
+Add a regexp to the list of ignored patterns. Can be called multiple times.
+
 =cut
 
 sub catalyst_ignore {
@@ -104,6 +127,7 @@ sub catalyst_ignore {
 # Workaround for a namespace conflict
 sub catalyst_par {
     my ( $self, $par ) = @_;
+    $par ||= '';
     return if $SAFETY;
     $SAFETY++;
     my $name  = $self->name;
@@ -111,9 +135,13 @@ sub catalyst_par {
     $usage =~ s/"/\\"/g;
     my $class_string = join "', '", @CLASSES;
     $class_string = "'$class_string'" if $class_string;
+    local $Data::Dumper::Indent = 0;
+    local $Data::Dumper::Terse = 1;
+    local $Data::Dumper::Pad = ' ';
+    my $paropts_string = Dumper(\%PAROPTS) || "{ }";
     $self->postamble(<<EOF);
 catalyst_par :: all
-\t\$(NOECHO) \$(PERL) -Ilib -Minc::Module::Install -MModule::Install::Catalyst -e"Catalyst::Module::Install::_catalyst_par( '$par', '$name', { CLASSES => [$class_string], CORE => $CORE, ENGINE => '$ENGINE', MULTIARCH => $MULTIARCH, SCRIPT => '$SCRIPT', USAGE => q#$usage# } )"
+\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# } )"
 EOF
     print <<EOF;
 Please run "make catalyst_par" to create the PAR package!
@@ -126,7 +154,7 @@ EOF
 
 sub catalyst_par_core {
     my ( $self, $core ) = @_;
-    $core ? ( $CORE = $core ) : $CORE++;
+    $core ? ( $PAROPTS{'B'} = $core ) : $PAROPTS{'B'}++;
 }
 
 =head2 catalyst_par_classes(@clases)
@@ -153,7 +181,47 @@ sub catalyst_par_engine {
 
 sub catalyst_par_multiarch {
     my ( $self, $multiarch ) = @_;
-    $multiarch ? ( $MULTIARCH = $multiarch ) : $MULTIARCH++;
+    $multiarch ? ( $PAROPTS{'m'} = $multiarch ) : $PAROPTS{'m'}++;
+}
+
+=head2 catalyst_par_options($optstring)
+
+This command can be used in Makefile.PL to customise the PAR creation process.
+The parameter "$optstring" contains a string with arguments in identical syntax
+as arguments of B<pp> command from L<PAR::Packer> package.
+
+Example:
+
+    # part of your Makefile.PL
+    
+    catalyst_par_options("-v -f Bleach -z 9");
+    # verbose mode; use filter 'Bleach'; zip with compression level 9
+    catalyst;
+
+Note1: There is no reason to use catalyst_par_options() command multiple times
+as you can spacify in "$optstring" as many options as you want. Still, it
+is supported to call catalyst_par_options(...) more than once - in that case the
+specified options are merged (however it does merge arrays with values specified
+by parameters -a -A -X -f -F -I -l -M).
+
+Note2: By default the options "-x=1 -p=1 -n=0 -o=<appname>.par" are set. You can
+override them by catalyst_par_options(); however B<don't change them> unless you 
+exactly know what you are doing.
+
+=cut
+
+sub catalyst_par_options {
+    my ( $self, $optstring ) = @_;
+    my %o = ();
+    eval "use PAR::Packer ()";
+    if ($@) {
+        warn "WARNING: catalyst_par_options ignored - you need PAR::Packer\n"
+    }
+    else {
+        Getopt::Long::Configure ("no_ignore_case");
+        Getopt::Long::GetOptionsFromString($optstring, \%o, PAR::Packer->options);
+        %PAROPTS = ( %PAROPTS, %o);
+    }   
 }
 
 =head2 catalyst_par_script($script)
@@ -188,8 +256,7 @@ sub _catalyst_par {
     my $CLASSES   = $opts->{CLASSES} || [];
     my $USAGE     = $opts->{USAGE};
     my $SCRIPT    = $opts->{SCRIPT};
-    my $MULTIARCH = $opts->{MULTIARCH};
-    my $CORE      = $opts->{CORE};
+    my $PAROPTS   = $opts->{PAROPTS};
 
     my $name = $class_name;
     $name =~ s/::/_/g;
@@ -298,11 +365,13 @@ EOF
         'x' => 1,
         'n' => 0,
         'o' => $par,
-        'a' => [ grep( !/par.pl/, glob '.' ) ],
         'p' => 1,
-        'B' => $CORE,
-        'm' => $MULTIARCH
+        %{$PAROPTS},
+        # user defined options override the harcoded defaults
     );
+    # do not replace the whole $opt{'a'} array; just push required default value
+    push @{$opt{'a'}}, grep( !/par.pl/, glob '.' );  
+
     App::Packer::PAR->new(
         frontend  => 'Module::ScanDeps',
         backend   => 'PAR::Packer',
@@ -325,7 +394,7 @@ Catalyst Contributors, see Catalyst.pm
 
 =head1 LICENSE
 
-This library is free software, you can redistribute it and/or modify it under
+This library is free software. You can redistribute it and/or modify it under
 the same terms as Perl itself.
 
 =cut