lib/Module/Build/PPMMaker.pm

filter: Statementstmt 85.9% 61 / 71 Branchbran 40.0% 8 / 20 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 2 totaltotal 73.5% 78 / 106 CC 18 SCAR 30.3
CC
18
Cov
74%
make_ppd
29.8
_varchname
2.0
BEGIN
1.0
CRAP 20.7
« blib/lib/Module/Build/Platform/Windows.pm ↑ Summary blib/lib/Module/Build/ConfigData.pm »
1 package Module::Build::PPMMaker;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.4234';
8 2 $VERSION = eval $VERSION;
9  
10 # This code is mostly borrowed from ExtUtils::MM_Unix 6.10_03, with a
11 # few tweaks based on the PPD spec at
12 # http://www.xav.com/perl/site/lib/XML/PPD.html
13  
14 # The PPD spec is based on <http://www.w3.org/TR/NOTE-OSD>
15  
16 5 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
17 5 my $package = shift;
18 5 return bless {@_}, $package;
19 }
20  
21 5 ▶sub make_ppd {
Subroutine make_ppd: called CC=17 SCAR=33.9
Pod undocumented
22 5 my ($self, %args) = @_;
23 5 my $build = delete $args{build};
24  
25 5 my @codebase;
26 5 ▶ if (exists $args{codebase}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'codebase'}) { } 2 3 5
27 0 ▶ @codebase = ref $args{codebase} ? @{$args{codebase}} : ($args{codebase});
Branch: 1 branch
BranchTrueFalseTotal
ref $args{'codebase'} ? : 0 2 2
28 } else {
29 3 my $distfile = $build->ppm_name . '.tar.gz';
30 3 print "Using default codebase '$distfile'\n";
31 3 @codebase = ($distfile);
32 }
33  
34 5 my %dist;
35 5 foreach my $info (qw(name author abstract version)) {
36 20 my $method = "dist_$info";
37 20 ▶ $dist{$info} = $build->$method() or die "Can't determine distribution's $info\n";
Branch: 1 branch
BranchTrueFalseTotal
$dist{$info} = $build->$method or die "Can't determine distribution's $info\n" 20 0 20
38 }
39  
40 5 $self->_simple_xml_escape($_) foreach $dist{abstract}, @{$dist{author}};
41  
42 # TODO: could add <LICENSE HREF=...> tag if we knew what the URLs were for
43 # various licenses
44 5 my $ppd = <<"PPD";
45 <SOFTPKG NAME=\"$dist{name}\" VERSION=\"$dist{version}\">
46 <ABSTRACT>$dist{abstract}</ABSTRACT>
47 5 @{[ join "\n", map " <AUTHOR>$_</AUTHOR>", @{$dist{author}} ]}
48 <IMPLEMENTATION>
49 PPD
50  
51 # We don't include recommended dependencies because PPD has no way
52 # to distinguish them from normal dependencies. We don't include
53 # build_requires dependencies because the PPM installer doesn't
54 # build or test before installing. And obviously we don't include
55 # conflicts either.
56  
57 5 foreach my $type (qw(requires)) {
58 5 my $prereq = $build->$type();
59 5 foreach my $modname (sort keys %$prereq) {
60 0 ▶ next if $modname eq 'perl';
Branch: 1 branch
BranchTrueFalseTotal
if $modname eq "perl" 0 0 0
61  
62 0 my $min_version = '0.0';
63 0 foreach my $c ($build->_parse_conditions($prereq->{$modname})) {
64 0 my ($op, $version) = $c =~ /^\s* (<=?|>=?|==|!=) \s* ([\w.]+) \s*$/x;
65  
66 # This is a nasty hack because it fails if there is no >= op
67 0 ▶ if ($op eq '>=') {
Branch: 1 branch
BranchTrueFalseTotal
if ($op eq ">=") 0 0 0
68 0 $min_version = $version;
69 0 last;
70 }
71 }
72  
73 # PPM4 spec requires a '::' for top level modules
74 0 ▶ $modname .= '::' unless $modname =~ /::/;
Branch: 1 branch
BranchTrueFalseTotal
unless $modname =~ /::/ 0 0 0
75  
76 0 $ppd .= qq! <REQUIRE NAME="$modname" VERSION="$min_version" />\n!;
77 }
78 }
79  
80 # We only include these tags if this module involves XS, on the
81 # assumption that pure Perl modules will work on any OS.
82 5 ▶ if (keys %{$build->find_xs_files}) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$build->find_xs_files;}) 5 0 5
83 5 my $perl_version = $self->_ppd_version($build->perl_version);
84 5 $ppd .= sprintf(<<'EOF', $self->_varchname($build->config) );
85 <ARCHITECTURE NAME="%s" />
86 EOF
87 }
88  
89 5 foreach my $codebase (@codebase) {
90 5 $self->_simple_xml_escape($codebase);
91 5 $ppd .= sprintf(<<'EOF', $codebase);
92 <CODEBASE HREF="%s" />
93 EOF
94 }
95  
96 5 $ppd .= <<'EOF';
97 </IMPLEMENTATION>
98 </SOFTPKG>
99 EOF
100  
101 5 my $ppd_file = "$dist{name}.ppd";
102 5 ▶ open(my $fh, '>', $ppd_file)
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $ppd_file or die "Cannot write to ${ppd_file}: $!" 5 0 5
103 or die "Cannot write to $ppd_file: $!";
104  
105 binmode($fh, ":utf8")
106 5 ▶ if $] >= 5.008 && $Config{useperlio};
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008" and $Module::Build::PPMMaker::Config{"useperlio"} 5 0 5
Condition33%1/3
$] >= "5.008" and $Module::Build::PPMMaker::Config{"useperlio"}
!ll&&!rl&&r
005
MC/DC0%0/2
$] >= "5.008" and $Module::Build::PPMMaker::Config{"useperlio"}
$] >= "5.008" $Module::Build::PPMMaker::Config{"useperlio"}
Truth table33%1/3
A and B
A= $] >= "5.008"B= $Module::Build::PPMMaker::Config{"useperlio"}
ABresult
0X0
100
111
107 5 print $fh $ppd;
108 5 close $fh;
109  
110 5 return $ppd_file;
111 }
112  
113 7 ▶sub _ppd_version {
Subroutine _ppd_version: called CC=1 SCAR=0.0
114 7 my ($self, $version) = @_;
115  
116 # generates something like "0,18,0,0"
117 7 return join ',', (split(/\./, $version), (0)x4)[0..3];
118 }
119  
120 7 ▶sub _varchname { # Copied from PPM.pm
Subroutine _varchname: called CC=2 SCAR=7.0
121 7 my ($self, $config) = @_;
122 7 my $varchname = $config->{archname};
123 # Append "-5.8" to architecture name for Perl 5.8 and later
124 7 ▶ if ($] >= 5.008) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.008") 7 0 7
125 7 my $vstring = sprintf "%vd", $^V;
126 7 $vstring =~ s/\.\d+$//;
127 7 $varchname .= "-$vstring";
128 }
129 7 return $varchname;
130 }
131  
132 {
133 2 my %escapes = (
134 "\n" => "\\n",
135 '"' => '&quot;',
136 '&' => '&amp;',
137 '>' => '&gt;',
138 '<' => '&lt;',
139 );
140 2 my $rx = join '|', keys %escapes;
141  
142 15 ▶ sub _simple_xml_escape {
Subroutine _simple_xml_escape: called CC=1 SCAR=0.0
143 15 $_[1] =~ s/($rx)/$escapes{$1}/go;
144 }
145 }
146  
147 2 1;
148 __END__
« blib/lib/Module/Build/Platform/Windows.pm ↑ Summary blib/lib/Module/Build/ConfigData.pm »