DocSet/5005compat.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 74 CC 6 SCAR 19.3
CC
6
Cov
0%
import
12.0
open_file
12.0
warnings_pm
6.0
CRAP 6.9
1 package DocSet::5005compat;
2  
3 $DocSet::5005compat::VERSION = '0.01';
4  
5 use strict;
6 use Symbol ();
7 use File::Basename;
8 use File::Path;
9  
10 my %compat_files = (
11 'lib/warnings.pm' => \&warnings_pm,
12 );
13  
14 sub import {
15 if ($] >= 5.006) {
16 #make sure old compat stubs dont wipe out installed versions
17 unlink for keys %compat_files;
18 return;
19 }
20  
21 eval { require File::Spec::Functions; } or
22 die "this is only Perl $], you need to install File-Spec from CPAN";
23  
24 my $min_version = 0.82;
25 unless ($File::Spec::VERSION >= $min_version) {
26 die "you need to install File-Spec-$min_version or higher from CPAN";
27 }
28  
29 while (my ($file, $sub) = each %compat_files) {
30 $sub->($file);
31 }
32 }
33  
34 sub open_file {
35 my $file = shift;
36  
37 unless (-d 'lib') {
38 $file = "Apache-Test/$file";
39 }
40  
41 my $dir = dirname $file;
42  
43 unless (-d $dir) {
44 mkpath([$dir], 0, 0755);
45 }
46  
47 my $fh = Symbol::gensym();
48 print "creating $file\n";
49 open $fh, ">$file" or die "open $file: $!";
50  
51 return $fh;
52 }
53  
54 sub warnings_pm {
55 return if eval { require warnings };
56  
57 my $fh = open_file(shift);
58  
59 print $fh <<'EOF';
60 package warnings;
61  
62 sub import {}
63  
64 1;
65 EOF
66  
67 close $fh;
68 }
69  
70 1;
71  
72 =head1 NAME
73  
74 DocSet::5005compat - perl 5.005_03 compatibility module
75  
76 =head1 SYNOPSIS
77  
78 # must be loaded as early as possible
79 use DocSet::5005compat;
80  
81 =head1 DESCRIPTION
82  
83 This module encapsulates the functionalities/modules unavailable under
84 5.005_03.
85  
86 Currently it only creates the warnings pragma's shell, so the code like:
87  
88 use warnings;
89  
90 won't fail under 5.005_03.
91  
92 =head1 ORIGIN
93  
94 Borrowed from Apache::Test project.
95  
96 =cut
97