570802bb57ef747790572ccd139cf6df70a7f910
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Build.pm
1 package Catalyst::Build;
2
3 use strict;
4 use Module::Build;
5 use base 'Module::Build';
6 use Path::Class;
7 use File::Find 'find';
8
9 our @ignore =
10   qw/Build Build.PL Changes MANIFEST META.yml Makefile.PL Makefile README
11   _build blib lib script t/;
12
13 our $FAKE;
14 our $ignore = '^(' . join( '|', @ignore ) . ')$';
15
16 =head1 NAME
17
18 Catalyst::Build - Module::Build extension for Catalyst
19
20 =head1 SYNOPSIS
21
22 See L<Catalyst>
23
24 =head1 DESCRIPTION
25
26 L<Module::Build> extension for Catalyst.
27
28 =head1 METHODS
29
30 =item ACTION_install
31
32 =cut
33
34 sub ACTION_install {
35     my $self = shift;
36     $self->SUPER::ACTION_install;
37     $self->ACTION_install_extras;
38 }
39
40 =item ACTION_fakeinstall
41
42 =cut
43
44 sub ACTION_fakeinstall {
45     my $self = shift;
46     $self->SUPER::ACTION_fakeinstall;
47     local $FAKE = 1;
48     $self->ACTION_install_extras;
49 }
50
51 =item ACTION_install_extras
52
53 =cut
54
55 sub ACTION_install_extras {
56     my $self   = shift;
57     my $prefix = $self->{properties}{destdir} || '';
58     my $path   = dir(
59         $prefix,
60         $self->{config}{installsitelib},
61         split( '::', $self->{properties}{module_name} )
62     );
63     my @files = $self->_find_extras;
64     print "Installing extras to $path\n";
65     for (@files) {
66         $FAKE
67           ? print "$_ -> $path/$_ (FAKE)\n"
68           : $self->copy_if_modified( $_, $path );
69     }
70 }
71
72 sub _find_extras {
73     my $self = shift;
74     my @all  = glob '*';
75     my @files;
76     for my $file (@all) {
77         next if $file =~ /$ignore/;
78         if ( -d $file ) {
79             find(
80                 sub {
81                     return if -d;
82                     push @files, $File::Find::name;
83                 },
84                 $file
85             );
86         }
87         else { push @files, $file }
88     }
89     return @files;
90 }
91
92 =back
93
94 =head1 AUTHOR
95
96 Sebastian Riedel, C<sri@oook.de>
97
98 =head1 LICENSE
99
100 This library is free software . You can redistribute it and/or modify it under
101 the same terms as perl itself.
102
103 =cut
104
105 1;