blib/lib/WWW/PGXN/Distribution.pm

filter: Statementstmt 100% 90 / 90 Branchbran 85.2% 29 / 34 Conditioncond 53.8% 7 / 13 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 100% 28 / 28 Podpod 100% 17 / 17 totaltotal 91.5% 173 / 189 CC 25 SCAR 8.9
CC
25
Cov
92%
path_for_html_doc
5.0
_merge_meta
4.5
body_for_html_doc
3.0
CRAP 2.4
« blib/lib/WWW/PGXN.pm ↑ Summary blib/lib/WWW/PGXN/Extension.pm »
1 package WWW::PGXN::Distribution;
2  
3 9 ▶use 5.8.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 our $VERSION = v0.12.4;
8  
9 BEGIN {
10 # XXX Use DateTime for release date?
11 # XXX Use Software::License for license?
12 # XXX Use SemVer for versions?
13 9 ▶ for my $attr (qw(
Subroutine BEGIN: called CC=3 SCAR=11.0
14 abstract
15 license
16 name
17 version
18 description
19 generated_by
20 date
21 release_status
22 sha1
23 user
24 )) {
25 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 90 *{$attr} = sub {
27 47 ▶ $_[0]->_merge_meta unless $_[0]->{version};
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"version"} 2 45 47
28 47 $_[0]->{$attr}
29 90 };
30 }
31  
32 # Hash accessors.
33 9 for my $attr (qw(
34 no_index
35 prereqs
36 provides
37 resources
38 )) {
39 9 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 36 ▶ *{$attr} = sub { +{ %{ shift->{$attr} || {} } } };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{$attr} or {} 2 2 4
41 }
42 }
43  
44 sub new {
45 14 ▶ my ($class, $pgxn, $data) = @_;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
46 14 $data->{_pgxn} = $pgxn;
47 14 bless $data, $class;
48 }
49  
50 # Merging accessors.
51 sub releases {
52 14 ▶ my $self = shift;
Subroutine releases: called CC=2 SCAR=6.9
Pod documented
53 14 ▶ $self->_merge_by_dist unless $self->{releases};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"releases"} 1 13 14
54 14 return +{ %{ $self->{releases} } };
55 }
56  
57 sub docs {
58 3 ▶ my $self = shift;
Subroutine docs: called CC=3 SCAR=11.0
Pod documented
59 3 ▶ $self->_merge_meta unless $self->{version};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"version"} 1 2 3
60 3 ▶ return +{ %{ $self->{docs} || {} } };
Branch: 1 branch
BranchTrueFalseTotal
$self->{"docs"} or {} 1 2 3
61 }
62  
63 # List accessors.
64 1 ▶sub tags { @{ shift->{tags} || [] } }
Subroutine tags: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"tags"} or [] 0 1 1
65 1 ▶sub maintainers { @{ shift->{maintainer} || [] } }
Subroutine maintainers: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"maintainer"} or [] 0 1 1
66 1 ▶sub special_files { @{ shift->{special_files} || [] } }
Subroutine special_files: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"special_files"} or [] 0 1 1
67 3 ▶sub versions_for { map { $_->{version} } @{ shift->releases->{+shift} || [] } }
Subroutine versions_for: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->releases->{shift()} or [] 1 2 3
68  
69 # Instance methods.
70 7 ▶sub version_for { shift->releases->{+shift}[0]{version} }
Subroutine version_for: called CC=1 SCAR=0.0
Pod documented
71 3 ▶sub date_for { shift->releases->{+shift}[0]{date} }
Subroutine date_for: called CC=1 SCAR=0.0
Pod documented
72  
73 sub _merge_meta {
74 4 ▶ my $self = shift;
Subroutine _merge_meta: called CC=4 SCAR=15.0
75 4 my $rel = $self->{releases};
76 4 ▶ my $rels = $rel->{stable} || $rel->{testing} || $rel->{unstable};
Condition33%2/6
$rel->{'stable'} || $rel->{'testing'} || $rel->{'unstable'}
l!l&&r!l&&!r
400
$rel->{"stable"} or $rel->{"testing"}
l!l&&r!l&&!r
400
MC/DC0%0/3
$rel->{'stable'} || $rel->{'testing'} || $rel->{'unstable'}
$rel->{"stable"} $rel->{"testing"} $rel->{'unstable'}
Truth table25%1/4
A or B || C
A= $rel->{"stable"}B= $rel->{"testing"}C= $rel->{'unstable'}
ABCresult
1XX1
01X1
0011
0000
77 my $meta = $self->{_pgxn}->_fetch_json(meta => {
78 version => lc $rels->[0]{version},
79 dist => lc $self->{name},
80 4 ▶ }) || {};
Condition50%1/2
$self->{'_pgxn'}->_fetch_json('meta', {'version', lc $rels->[0]{'version'}, 'dist', lc $self->{'name'}}) || {}
l!l
40
MC/DC0%0/1
$self->{'_pgxn'}->_fetch_json('meta', {'version', lc $rels->[0]{'version'}, 'dist', lc $self->{'name'}}) || {}
$self->{'_pgxn'}->_fetch_json('meta', {'version', lc $rels->[0]{'version'}, 'dist', lc $self->{'name'}})
Truth table50%1/2
A
A= $self->{'_pgxn'}->_fetch_json('meta', {'version', lc $rels->[0]{'version'}, 'dist', lc $self->{'name'}})
Aresult
11
00
81 4 @{$self}{keys %{ $meta }} = values %{ $meta };
82 }
83  
84 sub _merge_by_dist {
85 2 ▶ my $self = shift;
Subroutine _merge_by_dist: called CC=2 SCAR=7.0
86 my $by_dist = $self->{_pgxn}->_fetch_json(dist => {
87 dist => lc $self->{name}
88 2 ▶ }) || {};
Condition50%1/2
$self->{'_pgxn'}->_fetch_json('dist', {'dist', lc $self->{'name'}}) || {}
l!l
20
MC/DC0%0/1
$self->{'_pgxn'}->_fetch_json('dist', {'dist', lc $self->{'name'}}) || {}
$self->{'_pgxn'}->_fetch_json('dist', {'dist', lc $self->{'name'}})
Truth table50%1/2
A
A= $self->{'_pgxn'}->_fetch_json('dist', {'dist', lc $self->{'name'}})
Aresult
11
00
89 2 @{$self}{keys %{ $by_dist }} = values %{ $by_dist };
90 }
91  
92 sub download_url {
93 1 ▶ my $self = shift;
Subroutine download_url: called CC=1 SCAR=0.0
Pod documented
94 1 $self->{_pgxn}->_url_for(download => {
95 dist => lc $self->name,
96 version => lc $self->version
97 });
98 }
99  
100 sub download_path {
101 1 ▶ my $self = shift;
Subroutine download_path: called CC=1 SCAR=0.0
Pod documented
102 1 $self->{_pgxn}->_path_for(download => {
103 dist => lc $self->name,
104 version => lc $self->version
105 });
106 }
107  
108 sub download_to {
109 2 ▶ my $self = shift;
Subroutine download_to: called CC=1 SCAR=0.0
Pod documented
110 $self->{_pgxn}->_download_to(shift, {
111 2 dist => lc $self->name,
112 version => lc $self->version
113 });
114 }
115  
116 sub source_url {
117 2 ▶ my $self = shift;
Subroutine source_url: called CC=2 SCAR=6.9
Pod documented
118 2 ▶ my $uri = $self->source_path or return;
Branch: 1 branch
BranchTrueFalseTotal
my $uri = $self->source_path or return 1 1 2
119 1 return URI->new($self->{_pgxn}->url . $uri);
120 }
121  
122 sub source_path {
123 4 ▶ my $self = shift;
Subroutine source_path: called CC=2 SCAR=6.9
Pod documented
124 4 ▶ my $tmpl = $self->{_pgxn}->_uri_templates->{source} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tmpl = $self->{"_pgxn"}->_uri_templates->{"source"} or return 2 2 4
125 2 return $tmpl->process(
126 dist => lc $self->name,
127 version => lc $self->version
128 );
129 }
130  
131 sub url_for_html_doc {
132 9 ▶ my $self = shift;
Subroutine url_for_html_doc: called CC=2 SCAR=6.9
Pod documented
133 9 ▶ my $uri = $self->path_for_html_doc(shift) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $uri = $self->path_for_html_doc(shift()) or return 5 4 9
134 4 return URI->new($self->{_pgxn}->url . $uri);
135 }
136  
137 sub path_for_html_doc {
138 14 ▶ my ($self, $path) = @_;
Subroutine path_for_html_doc: called CC=5 SCAR=16.1
Pod documented
139 14 ▶ $self->_merge_meta unless $self->{version};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"version"} 0 14 14
140 14 ▶ return unless $self->{docs} && $self->{docs}{$path};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"docs"} and $self->{"docs"}{$path} 5 9 14
Condition100%3/3
$self->{"docs"} and $self->{"docs"}{$path}
!ll&&!rl&&r
419
MC/DC100%2/2
$self->{"docs"} and $self->{"docs"}{$path}
$self->{"docs"} $self->{"docs"}{$path}
Truth table100%3/3
A and B
A= $self->{"docs"}B= $self->{"docs"}{$path}
ABresult
0X0
100
111
141  
142 9 ▶ my $tmpl = $self->{_pgxn}->_uri_templates->{htmldoc} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $tmpl = $self->{"_pgxn"}->_uri_templates->{"htmldoc"} or return 3 6 9
143 6 $tmpl->process(
144 dist => lc $self->name,
145 version => lc $self->version,
146 docpath => $path,
147 );
148 }
149  
150 sub body_for_html_doc {
151 5 ▶ my $self = shift;
Subroutine body_for_html_doc: called CC=3 SCAR=11.0
Pod documented
152 5 ▶ my $url = $self->url_for_html_doc(shift) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $url = $self->url_for_html_doc(shift()) or return 3 2 5
153 2 ▶ my $res = $self->{_pgxn}->_fetch($url) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $res = $self->{"_pgxn"}->_fetch($url) or return 0 2 2
154 2 utf8::decode $res->{content};
155 2 return $res->{content};
156 }
157  
158 9 1;
159  
160 __END__
161  
162 =head1 Name
163  
164 WWW::PGXN::Distribution - Distribution metadata fetched from PGXN
165  
166 =head1 Synopsis
167  
168 my $pgxn = WWW::PGXN->new( url => 'http://api.pgxn.org/' );
169 my $dist = $pgxn->get_distribution('pgTAP');
170 $dist->download_to('.');
171  
172 =head1 Description
173  
174 This module represents PGXN distribution metadata fetched from PGXN>. It is
175 not intended to be constructed directly, but via the
176 L<WWW::PGXN/get_distribution> method of L<WWW::PGXN>.
177  
178 =head1 Interface
179  
180 =begin private
181  
182 =head2 Constructor
183  
184 =head3 C<new>
185  
186 my $distribution = WWW::PGXN::Distribution->new($distribution, $data);
187  
188 Construct a new WWW::PGXN::Distribution object. The first argument must be
189 an instance of L<WWW::PGXN> that connected to the PGXN server. The second
190 argument must be the data fetched.
191  
192 =end private
193  
194 =head2 Instance Accessors
195  
196 =head3 C<name>
197  
198 my $name = $distribution->name;
199 $distribution->name($name);
200  
201 The name of the distribution.
202  
203 =head3 C<version>
204  
205 my $version = $distribution->version;
206 $distribution->version($version);
207  
208 The distribution version distribution. Returned as a string, but may be passed
209 to L<SemVer> for comparing versions.
210  
211 use SemVer;
212 my $version = SemVer->new( $distribution->version );
213  
214 This interface may be modified in the future to return a L<SemVer> object
215 itself.
216  
217 =head3 C<abstract>
218  
219 my $abstract = $distribution->abstract;
220 $distribution->abstract($abstract);
221  
222 The abstract for the distribution, a very brief description.
223  
224 =head3 C<license>
225  
226 my $license = $distribution->license;
227 $distribution->license($license);
228  
229 The license for the distribution, usually a simple string such as "gpl_3" or
230 "postgresql". See the L<PGXN Meta spec|http://pgxn.org/meta/spec.html#license>
231 for details.
232  
233 =head3 C<user>
234  
235 my $user = $distribution->user;
236 $distribution->user($user);
237  
238 The nickname of the user who released the distribution. Use the
239 L<WWW::PGXN/get_user> method of L<WWW::PGXN> to get more info on the user:
240  
241 my $user = $pgxn->get_user( $distribution->user );
242 say "Released by ", $user->name, ' <', $user->email, '>';
243  
244 =head3 C<description>
245  
246 my $description = $distribution->description;
247 $distribution->description($description);
248  
249 The distribution description, longer than the abstract.
250  
251 =head3 C<generated_by>
252  
253 my $generated_by = $distribution->generated_by;
254 $distribution->generated_by($generated_by);
255  
256 The name of the person or application that generated the metadata from which
257 this distribution object is created.
258  
259 =head3 C<date>
260  
261 my $date = $distribution->date;
262 $distribution->date($date);
263  
264 The date the distribution was released on PGXN. Represented as a string in
265 strict L<ISO-8601|http://en.wikipedia.org/wiki/ISO_8601> format and in the UTC
266 time zone. It may be parsed into a L<DateTime> object like so:
267  
268 use DateTime::Format::Strptime;
269 my $parser = DateTime::Format::Strptime->new(
270 pattern => '%FT%T',
271 time_zone => 'Z'
272 );
273 my $date = $parser->parse_datetime( '2010-10-29T22:46:45Z' );
274  
275 This interface may be modified in the future to return a L<DateTime> object
276 itself.
277  
278 =head3 C<release_status>
279  
280 my $release_status = $distribution->release_status;
281 $distribution->release_status($release_status);
282  
283 The release_status of the distribution. Should be one of:
284  
285 =over
286  
287 =item stable
288  
289 =item testing
290  
291 =item unstable
292  
293 =back
294  
295 =head3 C<sha1>
296  
297 my $sha1 = $distribution->sha1;
298 $distribution->sha1($sha1);
299  
300 The SHA-1 digest for the distribution. You can validate the distribution file
301 like so:
302  
303 use Digest::SHA1;
304 my $file = $distribution->download_to('.');
305 open my $fh, '<:raw', $file or die "Cannot open $file: $!\n";
306 my $sha1 = Digest::SHA1->new;
307 $sha1->addfile($fh);
308 warn $distribution->name . ' ' . $distribution->version
309 . ' does not validate against SHA1'
310 unless $sha1->hexdigest eq $distribution->sha1;
311  
312 =head2 Instance Methods
313  
314 =head3 C<maintainers>
315  
316 my @maintainers = $distribution->maintainers;
317  
318 Returns a list of the maintainers of the module. By the recommendation of the
319 L<PGXN Meta spec|http://pgxn.org/meta/spec.html#maintainer>, each should be
320 formatted with a name and email address suitable for on the recipient line of
321 an email.
322  
323 =head3 C<special_files>
324  
325 my @special_files = $distribution->special_files;
326  
327 Returns a list of special files in the distribution, such as C<Changes>,
328 C<README>, C<Makefile>, and C<META.json>, among others. Available only from an
329 API server. Returns an empty list for distributions fetched from a mirror.
330  
331 =head3 C<docs>
332  
333 my $docs = $distribution->docs;
334  
335 Returns a hash reference describing the documentation in the distribution. The
336 keys are paths to documentation files, and the values are hashes with at least
337 one key, C<title> which contains the title, of course. A second key,
338 C<abstract>, is optional and contains an abstract of the document. The
339 documentation files are stored as HTML and may be fetched via
340 C<body_for_html_doc()>.
341  
342 =head3 C<no_index>
343  
344 my $no_index = $distribution->no_index;
345  
346 Returns a hash reference describing files and directories that should not be
347 indexed by search engines or the PGXN infrastructure. The L<PGXN Meta
348 spec|http://pgxn.org/meta/spec.html#no_index> specifies that the structure of
349 this hash contain only these keys:
350  
351 =over
352  
353 =item C<file>
354  
355 An array of file names.
356  
357 =item C<directory>
358  
359 An array of directory names.
360  
361 =back
362  
363 The returned has will be empty if all files may be indexed.
364  
365 =head3 C<prereqs>
366  
367 my $prereqs = $distribution->prereqs;
368  
369 Returns a hash reference describing the prerequisites of the extension. The
370 L<PGXN Meta spec|http://pgxn.org/meta/spec.html#prereqs> dictates That the top
371 level keys of this hash may be any of:
372  
373 =over
374  
375 =item C<configure>
376  
377 =item C<build>
378  
379 =item C<test>
380  
381 =item C<runtime>
382  
383 =item C<develop>
384  
385 =back
386  
387 The value for each of these keys must be a hash reference describing the
388 prerequisites for that part of the extension lifecycle. The keys in this
389 secondary hash may be any of:
390  
391 =over
392  
393 =item C<requires>
394  
395 =item C<recommends>
396  
397 =item C<suggests>
398  
399 =back
400  
401 Each of these in turn points to another hash reference, the keys of which are
402 the names of the prerequisite extensions and the values are their minimum
403 required version numbers. See the
404 L<Prereq Spec|http://pgxn.org/meta/spec.html#Prereq.Spec> for further
405 explication of these phases and relationships. Here's an example of what a
406 typical C<prereqs> hash might look like:
407  
408 {
409 prereqs => {
410 runtime => {
411 requires => {
412 PostgreSQL => '8.0.0',
413 PostGIS => '1.5.0'
414 },
415 recommends => {
416 PostgreSQL => '8.4.0'
417 },
418 suggests => {
419 semver => 0
420 },
421 },
422 build => {
423 requires => {
424 prefix => 0
425 },
426 },
427 test => {
428 recommends => {
429 pgTAP => 0
430 },
431 }
432 }
433 }
434  
435 =head3 C<provides>
436  
437 my $provides = $distribution->provides;
438  
439 Returns a hash reference describing the resources provided by the
440 distribution. The keys are the names of the resources (generally extension
441 names) and their values are hash references describing them. The keys
442 available in these hashes include:
443  
444 =over
445  
446 =item C<file>
447  
448 The name of the file in which the resource is defined.
449  
450 =item C<version>
451  
452 The L<semantic version|SemVer> of the resource.
453  
454 =item C<abstract>
455  
456 A brief description of the resource.
457  
458 =item C<docfile>
459  
460 A path to the documentation file for the resource, if any.
461  
462 =item C<docpath>
463  
464 A path to the documentation for the resource, usually the same as C<docfile>
465 but without the file name extension. So if C<docfile> is F<docs/pair.txt>,
466 C<docpath> would be F<docs/pair>. Provided only by the API server. May be
467 present even if C<docfile> is not, since the API might have found the
468 documentation even if the release manager didn't specify it in the
469 F<META.json>.
470  
471 =back
472  
473 Here's an example of the structure for a simple distribution that provides a
474 single extension:
475  
476 {
477 pair => {
478 abstract => 'A key/value pair data type',
479 file => 'sql/pair.sql',
480 version => '0.1.1',
481 docfile => 'doc/pair.md',
482 docpath => 'doc/pair',
483 }
484 }
485  
486 See the <spec|http://pgxn.org/meta/spec.html#provides> for more information.
487  
488 =head3 C<releases>
489  
490 my $releases = $distribution->releases;
491  
492 Returns a hash reference providing version and date information for all
493 releases of the distribution. The hash reference must have one or more of the
494 following keys:
495  
496 =over
497  
498 =item C<stable>
499  
500 =item C<testing>
501  
502 =item C<unstable>
503  
504 An array reference containing hashes of versions and release dates of all
505 releases of the distribution with the named release status, ordered from most
506 to least recent.
507  
508 =back
509  
510 Here's an example of the C<releases> data structure:
511  
512 {
513 stable => [
514 { version => '0.1.1', date => '2010-10-22T16:32:52Z' },
515 { version => '0.1.0', date => '2010-10-19T03:59:54Z' }
516 ],
517 testing => [
518 { version => '0.0.1', date => '2010-09-23T14:23:52Z' }
519 ]
520 }
521  
522 =head3 C<resources>
523  
524 my $resources = $distribution->resources;
525  
526 Returns a hash reference describing the resources for the distribution. These
527 include source code repository information, bug reporting addresses, and the
528 like. Example:
529  
530 {
531 bugtracker => {
532 web => 'http://github.com/theory/kv-pair/issues/'
533 },
534 repository => {
535 type => 'git',
536 url => 'git://github.com/theory/kv-pair.git',
537 web => 'http://github.com/theory/kv-pair/'
538 },
539 }
540  
541 Read the
542 L<Resources section of the meta spec|http://pgxn.org/meta/spec.html#resources>
543 for all the details.
544  
545 =head3 C<tags>
546  
547 my @tags = $distribution->tags;
548  
549 Returns a list of the tags associated with the distribution. Each may be used
550 to look up further information about the tag via L<WWW::PGXN::Tag> objects
551 like so:
552  
553 for my $tag ( map { $pgxn->get_tag($_) } $distribution->tags ) {
554 say $tag->name;
555 }
556  
557 =head3 C<download_url>
558  
559 my $url = $distribution->download_url;
560  
561 The absolute URL for the distribution archive file on the mirror or API sever,
562 such as
563  
564 http://api.pgxn.org/dist/pair/pair-0.1.1.zip
565  
566 Or, for a file system URL:
567  
568 file:/path/to/mirror/dist/pair/pair-0.1.1.zip
569  
570 =head3 C<download_path>
571  
572 my $uri = $distribution->path;
573  
574 The path to the distribution archive file. That is, the path relative to any
575 PGXN mirror root. So rather than the full URL you'd get from the C<url>
576 method, you just get the path as derived from the distribution URI template,
577 for example:
578  
579 /dist/pair/pair-0.1.1.zip
580  
581 =head3 C<source_url>
582  
583 my $source_url = $distribution->source_url;
584  
585 The absolute URL to the unzipped source on the API server, suitable for
586 browsing. For example:
587  
588 http://api.pgxn.org/src/pair/pair-0.1.1/
589  
590 Or, for a file system URL:
591  
592 file:/path/to/mirror/src/pair/pair-0.1.1/
593  
594 If connected to a mirror, rather than an API server, C<undef> will be
595 returned.
596  
597 =head3 C<source_path>
598  
599 my $source_path = $distribution->source_path;
600  
601 The path to the unzipped, browsable distribution. That is, the path relative
602 to any PGXN mirror root. So rather than the full URL you'd get from the
603 C<source_url> method, you just get the path as derived from the distribution
604 URI template, for example:
605  
606 /src/pair/pair-0.1.1/
607  
608 =head3 C<download_to>
609  
610 my file = $distribution->download_to('.');
611 $distribution->download_to('myfile.zip');
612  
613 Downloads the distribution. Pass the name of the file to save to, or the name
614 of a directory. If a directory is specified, the file will be written with the
615 same name as it has on PGXN, such as C<pgtap-0.24.0.zip>. Either way, the name
616 of the file written will be returned. Regardless of the file's name, it will
617 always be a zip archive.
618  
619 =head3 C<version_for>
620  
621 my $version = $distribution->version_for('testing');
622  
623 Returns the most recent version for a release status, if any exists. The
624 supported release statuses are:
625  
626 =over
627  
628 =item C<stable>
629  
630 =item C<testing>
631  
632 =item C<unstable>
633  
634 =back
635  
636 These version numbers can be used to fetch information specific to a version:
637  
638 my $test_dist = $pgxn->get_distribution(
639 $distribution->name,
640 $distribution->version_for('testing'),
641 );
642  
643 =head3 C<date_for>
644  
645 my $date = $distribution->date_for('unstable');
646  
647 Like C<version_for()>, but returns the release date of the most recent version
648 for the given release status. The supported release statuses are:
649  
650 =over
651  
652 =item C<stable>
653  
654 =item C<testing>
655  
656 =item C<unstable>
657  
658 =back
659  
660 =head3 C<versions_for>
661  
662 my @versions = $distributions->versions_for('stable');
663  
664 Returns a list of the versions for a particular release status, if any. The
665 are returned in order from most to least recent.
666  
667 =head3 C<url_for_html_doc>
668  
669 # returns http://api.pgxn.org/dist/pair/pair-0.1.1/doc/pair.html
670 my $doc_url = $distribution->url_for_html_doc('doc/pair');
671  
672 The absolute URL to an HTML documentation file. Pass a document path to get
673 its URL. The keys in the C<docs> hash reference represent all known document
674 paths. If connected to a mirror, rather than an API server, C<undef> will be
675 returned. Otherwise, if not document exists at that path, an exception will be
676 thrown.
677  
678 =head3 C<path_for_html_doc>
679  
680 # returns /dist/pair/pair-0.1.1/doc/pair.html
681 my $doc_url = $distribution->path_for_html_doc('doc/pair');
682  
683 The path to an HTML documentation file. Pass a document path to get its URL.
684 The keys in the C<docs> hash reference represent all known document paths. If
685 connected to a mirror, rather than an API server, C<undef> will be returned.
686 Otherwise, if not document exists at that path, an exception will be thrown.
687  
688 =head3 C<body_for_html_doc>
689  
690 my $body = $distribution->body_for_html_doc('README');
691  
692 Returns the body of an HTML document. Pass in the path to the doc (minus a
693 suffix) to retrieve its contents. They keys in the hash returned by C<docs>
694 provide the paths for all docs included in a distribution.
695  
696 Note that docs are formatted as HTML fragments with no C<< <head> >> or
697 C<< <body> >> element, though they may be assumed to constitute the contents
698 of a C<< <body> >> element. They are also always encoded as UTF-8.
699  
700 The contents are all contained within a single C<< <div> >> element with the
701 ID C<pgxndoc>, and include a table of contents. Here's a simple example of the
702 body of a document:
703  
704 <div id="pgxndoc">
705 <div id="pgxntoc">
706 <h3>Contents</h3>
707 <ul class="pgxntocroot">
708 <li><a href="#Title">Title</a></li>
709 </ul>
710 </div>
711 <div id="pgxnbod">
712 <h1 id="Title"><a href="/">Title</a></h1>
713 <p>Blah blah blah</p>
714 <p>Body</p>
715 </div>
716 </div>
717  
718 The IDs used for contents are generated from C<h1>, C<h2>, and C<h3> elements;
719 all other IDs and classes begin with "pgxn" as seen in this example.
720  
721 =head1 See Also
722  
723 =over
724  
725 =item * L<WWW::PGXN>
726  
727 The main class to communicate with a PGXN mirror or API server.
728  
729 =back
730  
731 =head1 Support
732  
733 This module is stored in an open L<GitHub
734 repository|http://github.com/theory/www-pgxn/>. Feel free to fork and
735 contribute!
736  
737 Please file bug reports via L<GitHub
738 Issues|http://github.com/theory/www-pgxn/issues/> or by sending mail to
739 L<bug-WWW-PGXN@rt.cpan.org|mailto:bug-WWW-PGXN@rt.cpan.org>.
740  
741 =head1 Author
742  
743 David E. Wheeler <david@justatheory.com>
744  
745 =head1 Copyright and License
746  
747 Copyright (c) 2011 David E. Wheeler. Some Rights Reserved.
748  
749 This module is free software; you can redistribute it and/or modify it under
750 the same terms as Perl itself.
751  
752 =cut
« blib/lib/WWW/PGXN.pm ↑ Summary blib/lib/WWW/PGXN/Extension.pm »