/
perldoc.pm
127 lines (101 loc) · 2.7 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
# 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);
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',
);
$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: