| 1 | # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| 2 | # contributor license agreements. See the NOTICE file distributed with | ||
| 3 | # this work for additional information regarding copyright ownership. | ||
| 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| 5 | # (the "License"); you may not use this file except in compliance with | ||
| 6 | # the License. You may obtain a copy of the License at | ||
| 7 | # | ||
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | # | ||
| 10 | # Unless required by applicable law or agreed to in writing, software | ||
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | # See the License for the specific language governing permissions and | ||
| 14 | # limitations under the License. | ||
| 15 | # | ||
| 16 | package Apache::Test5005compat; | ||
| 17 | |||
| 18 | use strict; | ||
| 19 | use Symbol (); | ||
| 20 | use File::Basename; | ||
| 21 | use File::Path; | ||
| 22 | |||
| 23 | $Apache::Test5005compat::VERSION = '0.01'; | ||
| 24 | |||
| 25 | my %compat_files = ( | ||
| 26 | 'lib/warnings.pm' => \&warnings_pm, | ||
| 27 | ); | ||
| 28 | |||
| 29 | sub import { | ||
| 30 | if ($] >= 5.006) { | ||
| 31 | #make sure old compat stubs dont wipe out installed versions | ||
| 32 | unlink for keys %compat_files; | ||
| 33 | return; | ||
| 34 | } | ||
| 35 | |||
| 36 | eval { require File::Spec::Functions; } or | ||
| 37 | die "this is only Perl $], you need to install File-Spec from CPAN"; | ||
| 38 | |||
| 39 | my $min_version = 0.82; | ||
| 40 | unless ($File::Spec::VERSION >= $min_version) { | ||
| 41 | die "you need to install File-Spec-$min_version or higher from CPAN"; | ||
| 42 | } | ||
| 43 | |||
| 44 | while (my($file, $sub) = each %compat_files) { | ||
| 45 | $sub->($file); | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | sub open_file { | ||
| 50 | my $file = shift; | ||
| 51 | |||
| 52 | unless (-d 'lib') { | ||
| 53 | $file = "Apache-Test/$file"; | ||
| 54 | } | ||
| 55 | |||
| 56 | my $dir = dirname $file; | ||
| 57 | |||
| 58 | unless (-d $dir) { | ||
| 59 | mkpath([$dir], 0, 0755); | ||
| 60 | } | ||
| 61 | |||
| 62 | my $fh = Symbol::gensym(); | ||
| 63 | print "creating $file\n"; | ||
| 64 | open $fh, ">$file" or die "open $file: $!"; | ||
| 65 | |||
| 66 | return $fh; | ||
| 67 | } | ||
| 68 | |||
| 69 | sub warnings_pm { | ||
| 70 | return if eval { require warnings }; | ||
| 71 | |||
| 72 | my $fh = open_file(shift); | ||
| 73 | |||
| 74 | print $fh <<'EOF'; | ||
| 75 | package warnings; | ||
| 76 | |||
| 77 | sub import {} | ||
| 78 | |||
| 79 | 1; | ||
| 80 | EOF | ||
| 81 | |||
| 82 | close $fh; | ||
| 83 | } | ||
| 84 | |||
| 85 | 1; |