- Fixes for rt.cpan #17322 and #17331
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Build.pm
1 package Catalyst::Build;
2
3 use strict;
4 use Module::Build;
5 use Path::Class;
6 use File::Find 'find';
7
8 our @ISA;
9 eval "require Module::Build";
10 die "Please install Module::Build\n" if $@;
11 push @ISA, 'Module::Build';
12
13 our @ignore =
14   qw/Build Build.PL Changes MANIFEST META.yml Makefile.PL Makefile README
15   _build blib lib script t/;
16
17 our $FAKE;
18 our $ignore = '^(' . join( '|', @ignore ) . ')$';
19
20 =head1 NAME
21
22 Catalyst::Build - Module::Build extension for Catalyst
23
24 =head1 SYNOPSIS
25
26 See L<Catalyst>
27
28 =head1 DESCRIPTION
29
30 L<Module::Build> extension for Catalyst.
31
32 =head1 DEPRECATION NOTICE
33
34 This module is deprecated in favor of L<Module::Install::Catalyst>.
35
36 =head1 METHODS
37
38 =over 4
39
40 =item new
41
42 =cut
43
44 sub new {
45     my $class = shift;
46     my $self  = $class->SUPER::new(@_);
47
48     my $app_name = $self->{properties}{module_name};
49     warn <<"EOF";
50
51  Note:
52
53     The use of Build.PL for building and distributing Catalyst
54     applications is deprecated in Catalyst 5.58.
55
56     We recommend using the new Module::Install-based Makefile
57     system.  You can generate a new Makefile.PL for your application
58     by running:
59
60         catalyst.pl -force -makefile $app_name
61
62 EOF
63
64     return $self;
65 }
66
67 =item ACTION_install
68
69 =cut
70
71 sub ACTION_install {
72     my $self = shift;
73     $self->SUPER::ACTION_install;
74     $self->ACTION_install_extras;
75 }
76
77 =item ACTION_fakeinstall
78
79 =cut
80
81 sub ACTION_fakeinstall {
82     my $self = shift;
83     $self->SUPER::ACTION_fakeinstall;
84     local $FAKE = 1;
85     $self->ACTION_install_extras;
86 }
87
88 =item ACTION_install_extras
89
90 =cut
91
92 sub ACTION_install_extras {
93     my $self    = shift;
94     my $prefix  = $self->{properties}{destdir} || undef;
95     my $sitelib = $self->install_destination('lib');
96     my @path    = defined $prefix ? ( $prefix, $sitelib ) : ($sitelib);
97     my $path    = dir( @path, split( '::', $self->{properties}{module_name} ) );
98     my @files   = $self->_find_extras;
99     print "Installing extras to $path\n";
100     for (@files) {
101         $FAKE
102           ? print "$_ -> $path (FAKE)\n"
103           : $self->copy_if_modified( $_, $path );
104     }
105 }
106
107 sub _find_extras {
108     my $self = shift;
109     my @all  = glob '*';
110     my @files;
111     for my $file (@all) {
112         next if $file =~ /$ignore/;
113         if ( -d $file ) {
114             find(
115                 sub {
116                     return if -d;
117                     push @files, $File::Find::name;
118                 },
119                 $file
120             );
121         }
122         else { push @files, $file }
123     }
124     return @files;
125 }
126
127 =back
128
129 =head1 AUTHOR
130
131 Sebastian Riedel, C<sri@oook.de>
132
133 =head1 LICENSE
134
135 This library is free software, you can redistribute it and/or modify it under
136 the same terms as Perl itself.
137
138 =cut
139
140 1;