/
perldoc.pm
170 lines (134 loc) · 3.72 KB
/
perldoc.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Copyright (C) 2001-2008, Parrot Foundation.
=head1 NAME
config/auto/perldoc - Check whether perldoc works
=head1 DESCRIPTION
Determines whether F<perldoc> exists on the system and, if so, which
version of F<perldoc> it is.
More specifically, we look for the F<perldoc> associated with the
instance of F<perl> with which F<Configure.pl> was invoked.
=cut
package auto::perldoc;
use strict;
use warnings;
use File::Temp qw (tempfile );
use base qw(Parrot::Configure::Step);
use Parrot::Configure::Utils ':auto';
sub _init {
my $self = shift;
my %data;
$data{description} = q{Is perldoc installed};
$data{result} = q{};
return \%data;
}
sub runstep {
my ( $self, $conf ) = @_;
my $slash = $conf->data->get('slash');
my $cmd = $conf->data->get('scriptdirexp_provisional') . $slash . q{perldoc};
my ( $fh, $filename ) = tempfile( UNLINK => 1 );
my $content = capture_output("$cmd -ud $filename perldoc") || undef;
return 1 unless defined( $self->_initial_content_check($conf, $content) );
my $version = $self->_analyze_perldoc($cmd, $filename, $content);
_handle_version($conf, $version, $cmd);
my $TEMP_pod_build = <<'E_NOTE';
# the following part of the Makefile was built by 'config/auto/perldoc.pm'
E_NOTE
opendir OPS, 'src/ops' or die "opendir ops: $!";
my @ops = sort grep { !/^\./ && /\.ops$/ } readdir OPS;
closedir OPS;
my $TEMP_pod = join q{ } =>
map { my $t = $_; $t =~ s/\.ops$/.pod/; "ops/$t" } @ops;
my $new_perldoc = $conf->data->get('new_perldoc');
foreach my $ops (@ops) {
my $pod = $ops;
$pod =~ s/\.ops$/.pod/;
if ( $new_perldoc ) {
$TEMP_pod_build .= <<"END"
ops/$pod: ../src/ops/$ops
\t\$(PERLDOC_BIN) -ud ops/$pod ../src/ops/$ops
\t\$(CHMOD) 0644 ops/$pod
END
}
else {
$TEMP_pod_build .= <<"END"
ops/$pod: ../src/ops/$ops
\t\$(PERLDOC_BIN) -u ../ops/$ops > ops/$pod
\t\$(CHMOD) 0644 ../ops/$pod
END
}
}
$conf->data->set(
TEMP_pod => $TEMP_pod,
TEMP_pod_build => $TEMP_pod_build,
);
return 1;
}
sub _initial_content_check {
my $self = shift;
my ($conf, $content) = @_;
if (! defined $content) {
$conf->data->set(
has_perldoc => 0,
new_perldoc => 0,
perldoc => 'echo',
TEMP_pod => '',
TEMP_pod_build => '',
);
$self->set_result('no');
return;
}
else {
return 1;
}
}
sub _analyze_perldoc {
my $self = shift;
my ($cmd, $tmpfile, $content) = @_;
my $version;
if ( $content =~ m/^Unknown option:/ ) {
$content = capture_output("$cmd perldoc") || '';
if ($content =~ m/perldoc/) {
$version = $self->_handle_old_perldoc();
}
else {
$version = $self->_handle_no_perldoc();
}
}
elsif ( open my $FH, '<', $tmpfile ) {
local $/;
$content = <$FH>;
close $FH;
$version = 2;
$self->set_result('yes');
}
else {
$version = $self->_handle_no_perldoc();
}
unlink $tmpfile;
return $version;
}
sub _handle_old_perldoc {
my $self = shift;
$self->set_result('yes, old version');
return 1;
}
sub _handle_no_perldoc {
my $self = shift;
$self->set_result('failed');
return 0;
}
sub _handle_version {
my ($conf, $version, $cmd) = @_;
$conf->data->set(
has_perldoc => $version != 0 ? 1 : 0,
new_perldoc => $version == 2 ? 1 : 0
);
$conf->data->set( perldoc => $cmd ) if $version;
return 1;
}
1;
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: