Commit | Line | Data |
bb4e9162 |
1 | package Module::Build::PPMMaker; |
2 | |
3 | use strict; |
613f422f |
4 | use Config; |
7a827510 |
5 | use vars qw($VERSION); |
53fc1c7e |
6 | $VERSION = '0.35_14'; |
7a827510 |
7 | $VERSION = eval $VERSION; |
bb4e9162 |
8 | |
9 | # This code is mostly borrowed from ExtUtils::MM_Unix 6.10_03, with a |
10 | # few tweaks based on the PPD spec at |
11 | # http://www.xav.com/perl/site/lib/XML/PPD.html |
12 | |
13 | # The PPD spec is based on <http://www.w3.org/TR/NOTE-OSD> |
14 | |
15 | sub new { |
16 | my $package = shift; |
17 | return bless {@_}, $package; |
18 | } |
19 | |
20 | sub make_ppd { |
21 | my ($self, %args) = @_; |
22 | my $build = delete $args{build}; |
23 | |
24 | my @codebase; |
25 | if (exists $args{codebase}) { |
26 | @codebase = ref $args{codebase} ? @{$args{codebase}} : ($args{codebase}); |
27 | } else { |
28 | my $distfile = $build->ppm_name . '.tar.gz'; |
29 | print "Using default codebase '$distfile'\n"; |
30 | @codebase = ($distfile); |
31 | } |
32 | |
33 | my %dist; |
34 | foreach my $info (qw(name author abstract version)) { |
35 | my $method = "dist_$info"; |
36 | $dist{$info} = $build->$method() or die "Can't determine distribution's $info\n"; |
37 | } |
bb4e9162 |
38 | |
39 | $self->_simple_xml_escape($_) foreach $dist{abstract}, @{$dist{author}}; |
40 | |
41 | # TODO: could add <LICENSE HREF=...> tag if we knew what the URLs were for |
42 | # various licenses |
43 | my $ppd = <<"PPD"; |
44 | <SOFTPKG NAME=\"$dist{name}\" VERSION=\"$dist{version}\"> |
bb4e9162 |
45 | <ABSTRACT>$dist{abstract}</ABSTRACT> |
46 | @{[ join "\n", map " <AUTHOR>$_</AUTHOR>", @{$dist{author}} ]} |
47 | <IMPLEMENTATION> |
48 | PPD |
49 | |
bb4e9162 |
50 | # We don't include recommended dependencies because PPD has no way |
51 | # to distinguish them from normal dependencies. We don't include |
52 | # build_requires dependencies because the PPM installer doesn't |
53 | # build or test before installing. And obviously we don't include |
54 | # conflicts either. |
613f422f |
55 | |
bb4e9162 |
56 | foreach my $type (qw(requires)) { |
57 | my $prereq = $build->$type(); |
58 | while (my ($modname, $spec) = each %$prereq) { |
59 | next if $modname eq 'perl'; |
60 | |
61 | my $min_version = '0.0'; |
62 | foreach my $c ($build->_parse_conditions($spec)) { |
63 | my ($op, $version) = $c =~ /^\s* (<=?|>=?|==|!=) \s* ([\w.]+) \s*$/x; |
64 | |
65 | # This is a nasty hack because it fails if there is no >= op |
66 | if ($op eq '>=') { |
67 | $min_version = $version; |
68 | last; |
69 | } |
70 | } |
71 | |
613f422f |
72 | # PPM4 spec requires a '::' for top level modules |
73 | $modname .= '::' unless $modname =~ /::/; |
bb4e9162 |
74 | |
613f422f |
75 | $ppd .= qq! <REQUIRE NAME="$modname" VERSION="$min_version" />\n!; |
bb4e9162 |
76 | } |
77 | } |
78 | |
79 | # We only include these tags if this module involves XS, on the |
613f422f |
80 | # assumption that pure Perl modules will work on any OS. |
bb4e9162 |
81 | if (keys %{$build->find_xs_files}) { |
82 | my $perl_version = $self->_ppd_version($build->perl_version); |
613f422f |
83 | $ppd .= sprintf(<<'EOF', $self->_varchname($build->config) ); |
bb4e9162 |
84 | <ARCHITECTURE NAME="%s" /> |
85 | EOF |
86 | } |
87 | |
88 | foreach my $codebase (@codebase) { |
89 | $self->_simple_xml_escape($codebase); |
90 | $ppd .= sprintf(<<'EOF', $codebase); |
91 | <CODEBASE HREF="%s" /> |
92 | EOF |
93 | } |
94 | |
95 | $ppd .= <<'EOF'; |
96 | </IMPLEMENTATION> |
97 | </SOFTPKG> |
98 | EOF |
99 | |
100 | my $ppd_file = "$dist{name}.ppd"; |
101 | my $fh = IO::File->new(">$ppd_file") |
102 | or die "Cannot write to $ppd_file: $!"; |
613f422f |
103 | |
104 | $fh->binmode(":utf8") |
105 | if $fh->can('binmode') && $] >= 5.008 && $Config{useperlio}; |
bb4e9162 |
106 | print $fh $ppd; |
107 | close $fh; |
108 | |
109 | return $ppd_file; |
110 | } |
111 | |
112 | sub _ppd_version { |
113 | my ($self, $version) = @_; |
114 | |
115 | # generates something like "0,18,0,0" |
116 | return join ',', (split(/\./, $version), (0)x4)[0..3]; |
117 | } |
118 | |
119 | sub _varchname { # Copied from PPM.pm |
120 | my ($self, $config) = @_; |
121 | my $varchname = $config->{archname}; |
122 | # Append "-5.8" to architecture name for Perl 5.8 and later |
94410036 |
123 | if ($] >= 5.008) { |
124 | my $vstring = sprintf "%vd", $^V; |
125 | $vstring =~ s/\.\d+$//; |
126 | $varchname .= "-$vstring"; |
bb4e9162 |
127 | } |
128 | return $varchname; |
129 | } |
130 | |
131 | { |
132 | my %escapes = ( |
133 | "\n" => "\\n", |
134 | '"' => '"', |
135 | '&' => '&', |
136 | '>' => '>', |
137 | '<' => '<', |
138 | ); |
139 | my $rx = join '|', keys %escapes; |
53fc1c7e |
140 | |
bb4e9162 |
141 | sub _simple_xml_escape { |
142 | $_[1] =~ s/($rx)/$escapes{$1}/go; |
143 | } |
144 | } |
145 | |
146 | 1; |
147 | __END__ |
148 | |
149 | |
150 | =head1 NAME |
151 | |
152 | Module::Build::PPMMaker - Perl Package Manager file creation |
153 | |
154 | |
155 | =head1 SYNOPSIS |
156 | |
157 | On the command line, builds a .ppd file: |
158 | ./Build ppd |
159 | |
160 | |
161 | =head1 DESCRIPTION |
162 | |
163 | This package contains the code that builds F<.ppd> "Perl Package |
164 | Description" files, in support of ActiveState's "Perl Package |
165 | Manager". Details are here: |
166 | L<http://aspn.activestate.com/ASPN/Downloads/ActivePerl/PPM/> |
167 | |
168 | |
169 | =head1 AUTHOR |
170 | |
77e96e88 |
171 | Dave Rolsky <autarch@urth.org>, Ken Williams <kwilliams@cpan.org> |
bb4e9162 |
172 | |
173 | |
174 | =head1 COPYRIGHT |
175 | |
77e96e88 |
176 | Copyright (c) 2001-2006 Ken Williams. All rights reserved. |
bb4e9162 |
177 | |
178 | This library is free software; you can redistribute it and/or |
179 | modify it under the same terms as Perl itself. |
180 | |
181 | |
182 | =head1 SEE ALSO |
183 | |
184 | perl(1), Module::Build(3) |
185 | |
186 | =cut |