This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Update Module-Build to CPAN version 0.4204
[perl5.git] / cpan / Module-Build / lib / Module / Build / Platform / MacOS.pm
CommitLineData
bb4e9162
YST
1package Module::Build::Platform::MacOS;
2
3use strict;
7a827510 4use vars qw($VERSION);
71213e49 5$VERSION = '0.4204';
7a827510 6$VERSION = eval $VERSION;
bb4e9162 7use Module::Build::Base;
0ec9ad96
SP
8use vars qw(@ISA);
9@ISA = qw(Module::Build::Base);
bb4e9162
YST
10
11use ExtUtils::Install;
12
dc8021d3 13sub have_forkpipe { 0 }
a314697d 14
bb4e9162
YST
15sub new {
16 my $class = shift;
17 my $self = $class->SUPER::new(@_);
53fc1c7e 18
bb4e9162 19 # $Config{sitelib} and $Config{sitearch} are, unfortunately, missing.
77e96e88
RGS
20 foreach ('sitelib', 'sitearch') {
21 $self->config($_ => $self->config("install$_"))
22 unless $self->config($_);
23 }
53fc1c7e 24
bb4e9162 25 # For some reason $Config{startperl} is filled with a bunch of crap.
77e96e88
RGS
26 (my $sp = $self->config('startperl')) =~ s/.*Exit \{Status\}\s//;
27 $self->config(startperl => $sp);
53fc1c7e 28
bb4e9162
YST
29 return $self;
30}
31
32sub make_executable {
33 my $self = shift;
34 require MacPerl;
35 foreach (@_) {
36 MacPerl::SetFileInfo('McPL', 'TEXT', $_);
37 }
38}
39
40sub dispatch {
41 my $self = shift;
42
43 if( !@_ and !@ARGV ) {
44 require MacPerl;
53fc1c7e 45
bb4e9162
YST
46 # What comes first in the action list.
47 my @action_list = qw(build test install);
48 my %actions = map {+($_, 1)} $self->known_actions;
49 delete @actions{@action_list};
50 push @action_list, sort { $a cmp $b } keys %actions;
51
52 my %toolserver = map {+$_ => 1} qw(test disttest diff testdb);
53 foreach (@action_list) {
54 $_ .= ' *' if $toolserver{$_};
55 }
53fc1c7e 56
bb4e9162
YST
57 my $cmd = MacPerl::Pick("What build command? ('*' requires ToolServer)", @action_list);
58 return unless defined $cmd;
59 $cmd =~ s/ \*$//;
60 $ARGV[0] = ($cmd);
53fc1c7e 61
bb4e9162
YST
62 my $args = MacPerl::Ask('Any extra arguments? (ie. verbose=1)', '');
63 return unless defined $args;
64 push @ARGV, $self->split_like_shell($args);
65 }
53fc1c7e 66
bb4e9162
YST
67 $self->SUPER::dispatch(@_);
68}
69
70sub ACTION_realclean {
71 my $self = shift;
72 chmod 0666, $self->{properties}{build_script};
73 $self->SUPER::ACTION_realclean;
74}
75
76# ExtUtils::Install has a hard-coded '.' directory in versions less
77# than 1.30. We use a sneaky trick to turn that into ':'.
78#
79# Note that we do it here in a cross-platform way, so this code could
80# actually go in Module::Build::Base. But we put it here to be less
81# intrusive for other platforms.
82
83sub ACTION_install {
84 my $self = shift;
53fc1c7e 85
bb4e9162
YST
86 return $self->SUPER::ACTION_install(@_)
87 if eval {ExtUtils::Install->VERSION('1.30'); 1};
53fc1c7e 88
bb4e9162
YST
89 local $^W = 0; # Avoid a 'redefine' warning
90 local *ExtUtils::Install::find = sub {
91 my ($code, @dirs) = @_;
92
93 @dirs = map { $_ eq '.' ? File::Spec->curdir : $_ } @dirs;
94
95 return File::Find::find($code, @dirs);
96 };
53fc1c7e 97
bb4e9162
YST
98 return $self->SUPER::ACTION_install(@_);
99}
100
1011;
102__END__
103
104=head1 NAME
105
106Module::Build::Platform::MacOS - Builder class for MacOS platforms
107
108=head1 DESCRIPTION
109
110The sole purpose of this module is to inherit from
111C<Module::Build::Base> and override a few methods. Please see
112L<Module::Build> for the docs.
113
23837600 114=head2 Overridden Methods
bb4e9162
YST
115
116=over 4
117
118=item new()
119
120MacPerl doesn't define $Config{sitelib} or $Config{sitearch} for some
121reason, but $Config{installsitelib} and $Config{installsitearch} are
122there. So we copy the install variables to the other location
123
124=item make_executable()
125
126On MacOS we set the file type and creator to MacPerl so it will run
127with a double-click.
128
129=item dispatch()
130
131Because there's no easy way to say "./Build test" on MacOS, if
132dispatch is called with no arguments and no @ARGV a dialog box will
133pop up asking what action to take and any extra arguments.
134
135Default action is "test".
136
137=item ACTION_realclean()
138
139Need to unlock the Build program before deleting.
140
141=back
142
143=head1 AUTHOR
144
145Michael G Schwern <schwern@pobox.com>
146
147
148=head1 SEE ALSO
149
150perl(1), Module::Build(3), ExtUtils::MakeMaker(3)
151
152=cut