| 1 | package Devel::Required; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | # set version information | ||||||||||||||||||
| 4 | 3 | $VERSION= '0.18'; | |||||||||||||||||
| 5 | |||||||||||||||||||
| 6 | # make sure we do everything by the book from now on | ||||||||||||||||||
| 7 | 3 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 8 | 3 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 9 | 3 | ▶ | use ExtUtils::MakeMaker (); | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 10 | |||||||||||||||||||
| 11 | # initializations | ||||||||||||||||||
| 12 | 3 | my @TEXT; # list with text-file conversion | |||||||||||||||||
| 13 | my @POD; # list with pod-file conversion | ||||||||||||||||||
| 14 | 3 | my $INSTALLATION; # any installation information | |||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | # replace WriteMakefile with our own copy | ||||||||||||||||||
| 17 | 3 | ▶ | BEGIN { | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 18 | 3 | ▶ | no warnings 'redefine'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 19 | 3 | ▶ | no strict 'refs'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 20 | 3 | my $subname= 'ExtUtils::MakeMaker::WriteMakefile'; | |||||||||||||||||
| 21 | 3 | my $old= \&{$subname}; | |||||||||||||||||
| 22 | 5 | ▶ | *$subname= sub { | ||||||||||||||||
|
Subroutine
__ANON__: called CC=16 SCAR=27.8
| |||||||||||||||||||
| 23 | |||||||||||||||||||
| 24 | # perform the old sub with parameters | ||||||||||||||||||
| 25 | 5 | @_= @_; # quick fix for brokennes in 5.9.5, as suggested by rgs | |||||||||||||||||
| 26 | 5 | $old->( @_ ); | |||||||||||||||||
| 27 | |||||||||||||||||||
| 28 | # initializations | ||||||||||||||||||
| 29 | 5 | my $pod; # pod filename to change | |||||||||||||||||
| 30 | my $modules; # hash reference to the module info | ||||||||||||||||||
| 31 | 5 | my $required; # required text to replace | |||||||||||||||||
| 32 | 5 | my $version; # version text to replace | |||||||||||||||||
| 33 | |||||||||||||||||||
| 34 | # each key and value pair passed to original WriteMakefile | ||||||||||||||||||
| 35 | 5 | ▶ | while (@_) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 36 | 14 | my ( $key, $value )= ( shift, shift ); | |||||||||||||||||
| 37 | |||||||||||||||||||
| 38 | # main module file | ||||||||||||||||||
| 39 | 14 | ▶ | if ( $key eq 'VERSION_FROM' ) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 40 | 5 | $pod= $value; | |||||||||||||||||
| 41 | } | ||||||||||||||||||
| 42 | |||||||||||||||||||
| 43 | # required modules hash ref | ||||||||||||||||||
| 44 | elsif ($key eq 'PREREQ_PM') { | ||||||||||||||||||
| 45 | 4 | $modules= $value; | |||||||||||||||||
| 46 | } | ||||||||||||||||||
| 47 | |||||||||||||||||||
| 48 | =for Explanation: | ||||||||||||||||||
| 49 | Anything we don't handle is simply ignored. | ||||||||||||||||||
| 50 | |||||||||||||||||||
| 51 | =cut | ||||||||||||||||||
| 52 | |||||||||||||||||||
| 53 | } | ||||||||||||||||||
| 54 | |||||||||||||||||||
| 55 | # use E::M's logic to obtain version information | ||||||||||||||||||
| 56 | 5 | ($version)= _slurp('Makefile') =~ m#\nVERSION = (\d+\.\d+)#s; | |||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | # text to insert | ||||||||||||||||||
| 59 | $required= join $/, | ||||||||||||||||||
| 60 | 6 | ▶ | map {" $_ (".($modules->{$_} || 'any').")"} | ||||||||||||||||
|
Condition100%2/2
$modules->{$_} || 'any'
MC/DC100%1/1
$modules->{$_} || 'any'
$modules->{$_}
Truth table100%2/2
A
A= $modules->{$_}
| |||||||||||||||||||
| 61 | 3 | sort {lc $a cmp lc $b} | |||||||||||||||||
| 62 | 5 | ▶ | keys %{$modules} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 63 | if $modules; | ||||||||||||||||||
| 64 | 5 | ▶ | $required ||= " (none)"; | ||||||||||||||||
|
Condition100%2/2
$required ||= " (none)"
MC/DC100%1/1
$required ||= " (none)"
$required
Truth table100%2/2
A
A= $required
| |||||||||||||||||||
| 65 | |||||||||||||||||||
| 66 | # convert all text files that matter | ||||||||||||||||||
| 67 | 5 | ▶ | foreach ( grep { -s } @TEXT ? @TEXT : 'README' ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 68 | 5 | ▶ | _convert( $_, "Version:$/", " $version", "$/$/" ) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 69 | if $version; | ||||||||||||||||||
| 70 | 5 | _convert( $_, "Required Modules:$/", $required, "$/$/" ); | |||||||||||||||||
| 71 | 5 | ▶ | _convert( $_, "Installation:$/", $INSTALLATION, "$/$/$/" ) | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 72 | if $INSTALLATION; | ||||||||||||||||||
| 73 | } | ||||||||||||||||||
| 74 | |||||||||||||||||||
| 75 | # convert all pod files that matter | ||||||||||||||||||
| 76 | 5 | ▶ | foreach ( grep { -s } @POD ? @POD : ($pod ? ($pod) : () ) ) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 77 | 5 | ▶ | _convert( | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 78 | $_, | ||||||||||||||||||
| 79 | "=head1 VERSION$/", | ||||||||||||||||||
| 80 | "$/This documentation describes version $version.$/", | ||||||||||||||||||
| 81 | "$/=" | ||||||||||||||||||
| 82 | ) if $version; | ||||||||||||||||||
| 83 | 5 | _convert( $_, "=head1 REQUIRED MODULES$/", "$/$required$/", "$/=" ); | |||||||||||||||||
| 84 | 5 | ▶ | _convert( $_, "=head1 INSTALLATION$/", "$/$INSTALLATION$/", "$/=") | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 85 | if $INSTALLATION; | ||||||||||||||||||
| 86 | } | ||||||||||||||||||
| 87 | 3 | }; | |||||||||||||||||
| 88 | } #BEGIN | ||||||||||||||||||
| 89 | |||||||||||||||||||
| 90 | # satisfy -require- | ||||||||||||||||||
| 91 | 3 | 1; | |||||||||||||||||
| 92 | |||||||||||||||||||
| 93 | #------------------------------------------------------------------------------- | ||||||||||||||||||
| 94 | # | ||||||||||||||||||
| 95 | # Standard Perl features | ||||||||||||||||||
| 96 | # | ||||||||||||||||||
| 97 | #------------------------------------------------------------------------------- | ||||||||||||||||||
| 98 | # IN: 1 class (ignored) | ||||||||||||||||||
| 99 | # 2..N key/value pairs | ||||||||||||||||||
| 100 | |||||||||||||||||||
| 101 | 4 | ▶ | sub import { | ||||||||||||||||
|
Subroutine
import: called CC=7 SCAR=19.8
| |||||||||||||||||||
| 102 | |||||||||||||||||||
| 103 | # lose the class | ||||||||||||||||||
| 104 | 4 | shift; | |||||||||||||||||
| 105 | |||||||||||||||||||
| 106 | # for all key value pairs | ||||||||||||||||||
| 107 | 4 | ▶ | while (@_) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 108 | 4 | my ( $type, $value )= ( shift, shift ); | |||||||||||||||||
| 109 | |||||||||||||||||||
| 110 | # set up text file processing | ||||||||||||||||||
| 111 | 4 | ▶ | if ( $type eq 'text' ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 112 | 0 | ▶ | push @TEXT, ref $value ? @{$value} : ($value); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 113 | } | ||||||||||||||||||
| 114 | |||||||||||||||||||
| 115 | # set up pod file processing | ||||||||||||||||||
| 116 | elsif ( $type eq 'pod' ) { | ||||||||||||||||||
| 117 | 0 | ▶ | push @POD,ref $value ? @{$value} : ($value); | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 118 | } | ||||||||||||||||||
| 119 | |||||||||||||||||||
| 120 | # set up maint/blead installation information | ||||||||||||||||||
| 121 | elsif ( $type eq 'maint_blead' ) { | ||||||||||||||||||
| 122 | 1 | $INSTALLATION= <<"INSTALLATION"; | |||||||||||||||||
| 123 | This distribution contains two versions of the code: one maintenance version | ||||||||||||||||||
| 124 | for versions of perl < $value (known as 'maint'), and the version currently in | ||||||||||||||||||
| 125 | development (known as 'blead'). The standard build for your perl version is: | ||||||||||||||||||
| 126 | |||||||||||||||||||
| 127 | perl Makefile.PL | ||||||||||||||||||
| 128 | make | ||||||||||||||||||
| 129 | make test | ||||||||||||||||||
| 130 | make install | ||||||||||||||||||
| 131 | |||||||||||||||||||
| 132 | This will try to test and install the "blead" version of the code. If the | ||||||||||||||||||
| 133 | Perl version does not support the "blead" version, then the running of the | ||||||||||||||||||
| 134 | Makefile.PL will *fail*. In such a case, one can force the installing of | ||||||||||||||||||
| 135 | the "maint" version of the code by doing: | ||||||||||||||||||
| 136 | |||||||||||||||||||
| 137 | perl Makefile.PL maint | ||||||||||||||||||
| 138 | |||||||||||||||||||
| 139 | Alternately, if you want automatic selection behavior, you can set the | ||||||||||||||||||
| 140 | AUTO_SELECT_MAINT_OR_BLEAD environment variable to a true value. On Unix-like | ||||||||||||||||||
| 141 | systems like so: | ||||||||||||||||||
| 142 | |||||||||||||||||||
| 143 | AUTO_SELECT_MAINT_OR_BLEAD=1 perl Makefile.PL | ||||||||||||||||||
| 144 | |||||||||||||||||||
| 145 | If your perl does not support the "blead" version of the code, then it will | ||||||||||||||||||
| 146 | automatically install the "maint" version of the code. | ||||||||||||||||||
| 147 | |||||||||||||||||||
| 148 | Please note that any additional parameters will simply be passed on to the | ||||||||||||||||||
| 149 | underlying Makefile.PL processing. | ||||||||||||||||||
| 150 | INSTALLATION | ||||||||||||||||||
| 151 | 1 | chomp $INSTALLATION; | |||||||||||||||||
| 152 | } | ||||||||||||||||||
| 153 | |||||||||||||||||||
| 154 | # huh? | ||||||||||||||||||
| 155 | else { | ||||||||||||||||||
| 156 | 1 | die qq{Don't know how to handle "$type"\n}; | |||||||||||||||||
| 157 | } | ||||||||||||||||||
| 158 | } | ||||||||||||||||||
| 159 | } #import | ||||||||||||||||||
| 160 | |||||||||||||||||||
| 161 | #------------------------------------------------------------------------------- | ||||||||||||||||||
| 162 | # | ||||||||||||||||||
| 163 | # Internal subroutines | ||||||||||||||||||
| 164 | # | ||||||||||||||||||
| 165 | #------------------------------------------------------------------------------- | ||||||||||||||||||
| 166 | # _convert | ||||||||||||||||||
| 167 | # | ||||||||||||||||||
| 168 | # Perform the indicated conversion on the specified file | ||||||||||||||||||
| 169 | # | ||||||||||||||||||
| 170 | # IN: 1 filename | ||||||||||||||||||
| 171 | # 2 string before to match | ||||||||||||||||||
| 172 | # 3 string to insert between before and after | ||||||||||||||||||
| 173 | # 4 string to match with after | ||||||||||||||||||
| 174 | |||||||||||||||||||
| 175 | 22 | ▶ | sub _convert { | ||||||||||||||||
|
Subroutine
_convert: called CC=7 SCAR=22.0
| |||||||||||||||||||
| 176 | 22 | my ( $filename, $before, $text, $after )= @_; | |||||||||||||||||
| 177 | 22 | local $_; | |||||||||||||||||
| 178 | |||||||||||||||||||
| 179 | =for Explanation: | ||||||||||||||||||
| 180 | We want to make sure that this also runs on pre 5.6 perl's, so we're | ||||||||||||||||||
| 181 | using old style open() | ||||||||||||||||||
| 182 | |||||||||||||||||||
| 183 | =cut | ||||||||||||||||||
| 184 | |||||||||||||||||||
| 185 | # there is something to process | ||||||||||||||||||
| 186 | 22 | ▶ | if ( my $contents= $_= _slurp($filename) ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 187 | |||||||||||||||||||
| 188 | # found and replaced text | ||||||||||||||||||
| 189 | 22 | ▶ | if ( s#$before(?:.*?)$after#$before$text$after#s ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 190 | |||||||||||||||||||
| 191 | # same as before (no action) | ||||||||||||||||||
| 192 | 22 | ▶ | if ($_ eq $contents) { | ||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||
| 193 | } | ||||||||||||||||||
| 194 | |||||||||||||||||||
| 195 | # successfully saved file with changes | ||||||||||||||||||
| 196 | elsif ( open( OUT, ">$filename" ) ) { | ||||||||||||||||||
| 197 | 16 | print OUT $_; | |||||||||||||||||
| 198 | 16 | ▶ | close OUT | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 199 | or die qq{Problem flushing "$filename": $!\n}; | ||||||||||||||||||
| 200 | 16 | ▶ | die qq{Did not properly install "$filename"\n} | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 201 | unless -s $filename == length; | ||||||||||||||||||
| 202 | } | ||||||||||||||||||
| 203 | |||||||||||||||||||
| 204 | # could not save file | ||||||||||||||||||
| 205 | else { | ||||||||||||||||||
| 206 | 0 | warn qq{Could not open "$filename" for writing: $!\n}; | |||||||||||||||||
| 207 | } | ||||||||||||||||||
| 208 | } | ||||||||||||||||||
| 209 | |||||||||||||||||||
| 210 | # couldn't replace | ||||||||||||||||||
| 211 | else { | ||||||||||||||||||
| 212 | 0 | $before =~ s#\s+$##s; | |||||||||||||||||
| 213 | 0 | warn qq{Could not find text marker "$before" in "$filename"\n}; | |||||||||||||||||
| 214 | } | ||||||||||||||||||
| 215 | } | ||||||||||||||||||
| 216 | } #_convert | ||||||||||||||||||
| 217 | |||||||||||||||||||
| 218 | #------------------------------------------------------------------------------- | ||||||||||||||||||
| 219 | # _slurp | ||||||||||||||||||
| 220 | # | ||||||||||||||||||
| 221 | # Return contents of given filename, a poor man's perl6 slurp(). Warns if | ||||||||||||||||||
| 222 | # it could not open the specified file | ||||||||||||||||||
| 223 | # | ||||||||||||||||||
| 224 | # IN: 1 filename | ||||||||||||||||||
| 225 | # OUT: 1 file contents | ||||||||||||||||||
| 226 | |||||||||||||||||||
| 227 | 27 | ▶ | sub _slurp { | ||||||||||||||||
|
Subroutine
_slurp: called CC=2 SCAR=7.1
| |||||||||||||||||||
| 228 | 27 | my ($filename)= @_; | |||||||||||||||||
| 229 | 27 | my $contents; | |||||||||||||||||
| 230 | |||||||||||||||||||
| 231 | # there is something to process | ||||||||||||||||||
| 232 | 27 | ▶ | if ( open( IN, $filename ) ) { | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 233 | 27 | $contents= do { local $/; <IN> }; | |||||||||||||||||
| 234 | 27 | close IN; | |||||||||||||||||
| 235 | } | ||||||||||||||||||
| 236 | |||||||||||||||||||
| 237 | # couldn't read file | ||||||||||||||||||
| 238 | else { | ||||||||||||||||||
| 239 | 0 | warn qq{Could not open "$filename" for reading: $!\n}; | |||||||||||||||||
| 240 | } | ||||||||||||||||||
| 241 | |||||||||||||||||||
| 242 | 27 | return $contents; | |||||||||||||||||
| 243 | } #_slurp | ||||||||||||||||||
| 244 | |||||||||||||||||||
| 245 | #------------------------------------------------------------------------------- | ||||||||||||||||||
| 246 | |||||||||||||||||||
| 247 | __END__ | ||||||||||||||||||