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