Do a complete par-ectomy, fixes RT#83936
[catagits/Catalyst-Devel.git] / lib / Module / Install / Catalyst.pm
1 package Module::Install::Catalyst;
2
3 use strict;
4
5 use base qw/ Module::Install::Base /;
6 our @ISA;
7 require Module::Install::Base;
8
9 use File::Find;
10 use FindBin;
11 use File::Copy::Recursive;
12 use File::Spec ();
13 use Getopt::Long ();
14 use Data::Dumper;
15
16 my $SAFETY = 0;
17
18 our @IGNORE =
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/;
22
23 =head1 NAME
24
25   Module::Install::Catalyst - Module::Install extension for Catalyst
26
27 =head1 SYNOPSIS
28
29   use inc::Module::Install;
30
31   name 'MyApp';
32   all_from 'lib/MyApp.pm';
33
34   requires 'Catalyst::Runtime' => '5.7014';
35
36   catalyst_ignore('.*temp');
37   catalyst_ignore('.*tmp');
38   catalyst;
39   WriteAll;
40
41 =head1 DESCRIPTION
42
43 L<Module::Install> extension for Catalyst.
44
45 =head1 METHODS
46
47 =head2 catalyst
48
49 Calls L<catalyst_files>. Should be the last catalyst*
50 command called in C<Makefile.PL>.
51
52 =cut
53
54 sub catalyst {
55     my $self = shift;
56
57     if($Module::Install::AUTHOR) {
58         $self->include("File::Copy::Recursive");
59     }
60
61     print <<EOF;
62 *** Module::Install::Catalyst
63 EOF
64     $self->catalyst_files;
65     print <<EOF;
66 *** Module::Install::Catalyst finished.
67 EOF
68 }
69
70 =head2 catalyst_files
71
72 Collect a list of all files a Catalyst application consists of and copy it
73 inside the blib/lib/ directory. Files and directories that match the modules
74 ignore list are excluded (see L<catalyst_ignore> and L<catalyst_ignore_all>).
75
76 =cut
77
78 sub catalyst_files {
79     my $self = shift;
80
81     chdir $FindBin::Bin;
82
83     my @files;
84     opendir CATDIR, '.';
85   CATFILES: for my $name ( readdir CATDIR ) {
86         for my $ignore (@IGNORE) {
87             next CATFILES if $name =~ /^$ignore$/;
88             next CATFILES if $name !~ /\w/;
89         }
90         push @files, $name;
91     }
92     closedir CATDIR;
93     my @path = split '-', $self->name;
94     for my $orig (@files) {
95         my $path = File::Spec->catdir( 'blib', 'lib', @path, $orig );
96         File::Copy::Recursive::rcopy( $orig, $path );
97     }
98 }
99
100 =head2 catalyst_ignore_all(\@ignore)
101
102 This function replaces the built-in default ignore list with the given list.
103
104 =cut
105
106 sub catalyst_ignore_all {
107     my ( $self, $ignore ) = @_;
108     @IGNORE = @$ignore;
109 }
110
111 =head2 catalyst_ignore(@ignore)
112
113 Add a regexp to the list of ignored patterns. Can be called multiple times.
114
115 =cut
116
117 sub catalyst_ignore {
118     my ( $self, @ignore ) = @_;
119     push @IGNORE, @ignore;
120 }
121
122 =head1 AUTHORS
123
124 Catalyst Contributors, see Catalyst.pm
125
126 =head1 LICENSE
127
128 This library is free software. You can redistribute it and/or modify it under
129 the same terms as Perl itself.
130
131 =cut
132
133 1;