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