1 # Copyright (C) 2001-2008, Parrot Foundation.
6 config/auto/perldoc - Check whether perldoc works
10 Determines whether F<perldoc> exists on the system and, if so, which
11 version of F<perldoc> it is.
13 More specifically, we look for the F<perldoc> associated with the
14 instance of F<perl> with which F<Configure.pl> was invoked.
18 package auto
::perldoc
;
23 use File
::Temp qw
(tempfile
);
24 use base
qw(Parrot::Configure::Step);
25 use Parrot
::Configure
::Utils
':auto';
31 $data{description
} = q{Is perldoc installed};
37 my ( $self, $conf ) = @_;
39 my $cmd = $conf->data->get_p5('scriptdirexp') . q{/perldoc};
40 my ( $fh, $filename ) = tempfile
( UNLINK
=> 1 );
41 my $content = capture_output
("$cmd -ud $filename perldoc") || undef;
43 return 1 unless defined( $self->_initial_content_check($conf, $content) );
45 my $version = $self->_analyze_perldoc($cmd, $filename, $content);
47 _handle_version
($conf, $version, $cmd);
49 my $TEMP_pod_build = <<'E_NOTE';
51 # the following part of the Makefile was built by 'config/auto/perldoc.pm'
55 opendir OPS, 'src/ops' or die "opendir ops: $!";
56 my @ops = sort grep { !/^\./ && /\.ops$/ } readdir OPS;
59 my $TEMP_pod = join q{ } =>
60 map { my $t = $_; $t =~ s/\.ops$/.pod/; "ops/$t" } @ops;
62 my $slash = $conf->data->get('slash');
63 my $new_perldoc = $conf->data->get('new_perldoc');
65 foreach my $ops (@ops) {
67 $pod =~ s/\.ops$/.pod/;
69 $TEMP_pod_build .= <<"END"
70 ops$slash$pod: ..${slash}src${slash}ops${slash}$ops
71 \t\$(PERLDOC) -ud ops${slash}$pod ..${slash}src${slash}ops${slash}$ops
72 \t\$(CHMOD) 0644 ops${slash}$pod
77 $TEMP_pod_build .= <<"END"
78 ops$slash$pod: ..${slash}src${slash}ops${slash}$ops
79 \t\$(PERLDOC) -u ..${slash}ops${slash}$ops > ops${slash}$pod
80 \t\$(CHMOD) 0644 ..${slash}ops${slash}$pod
87 TEMP_pod
=> $TEMP_pod,
88 TEMP_pod_build
=> $TEMP_pod_build,
94 sub _initial_content_check
{
96 my ($conf, $content) = @_;
97 if (! defined $content) {
103 TEMP_pod_build
=> '',
105 $self->set_result('no');
113 sub _analyze_perldoc
{
115 my ($cmd, $tmpfile, $content) = @_;
117 if ( $content =~ m/^Unknown option:/ ) {
118 $content = capture_output
("$cmd perldoc") || '';
119 if ($content =~ m/perldoc/) {
120 $version = $self->_handle_old_perldoc();
123 $version = $self->_handle_no_perldoc();
126 elsif ( open my $FH, '<', $tmpfile ) {
131 $self->set_result('yes');
134 $version = $self->_handle_no_perldoc();
140 sub _handle_old_perldoc
{
142 $self->set_result('yes, old version');
146 sub _handle_no_perldoc
{
148 $self->set_result('failed');
152 sub _handle_version
{
153 my ($conf, $version, $cmd) = @_;
155 has_perldoc
=> $version != 0 ?
1 : 0,
156 new_perldoc
=> $version == 2 ?
1 : 0
159 $conf->data->set( perldoc
=> $cmd ) if $version;
168 # cperl-indent-level: 4
171 # vim: expandtab shiftwidth=4: