| 1 | package WWW::PGXN::Extension; | ||||||||||
| 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 | |||||||||||
| 6 | 9 | our $VERSION = v0.12.4; | |||||||||
| 7 | |||||||||||
| 8 | BEGIN { | ||||||||||
| 9 | # Hash accessors. | ||||||||||
| 10 | 9 | ▶ | for my $k (qw( | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| |||||||||||
| 11 | stable | ||||||||||
| 12 | testing | ||||||||||
| 13 | unstable | ||||||||||
| 14 | )) { | ||||||||||
| 15 | 9 | ▶ | no strict 'refs'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 27 | ▶ | *{"$k\_info"} = sub { +{ %{ shift->{$k} || {} } } }; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||
| 17 | } | ||||||||||
| 18 | } | ||||||||||
| 19 | |||||||||||
| 20 | sub new { | ||||||||||
| 21 | 1 | ▶ | my ($class, $pgxn, $data) = @_; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 22 | 1 | $data->{_pgxn} = $pgxn; | |||||||||
| 23 | 1 | bless $data, $class; | |||||||||
| 24 | } | ||||||||||
| 25 | |||||||||||
| 26 | 1 | ▶ | sub name { shift->{extension} } | ||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 27 | 1 | ▶ | sub latest { shift->{latest} } | ||||||||
|
Subroutine
latest: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 28 | |||||||||||
| 29 | sub latest_info { | ||||||||||
| 30 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
latest_info: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 31 | 2 | return { %{ $self->{$self->{latest}} } }; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | sub stable_distribution { shift->_dist_for_status('stable') } | ||||||||
|
Subroutine
stable_distribution: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 35 | 1 | ▶ | sub testing_distribution { shift->_dist_for_status('testing') } | ||||||||
|
Subroutine
testing_distribution: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 36 | 1 | ▶ | sub unstable_distribution { shift->_dist_for_status('unstable') } | ||||||||
|
Subroutine
unstable_distribution: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 37 | |||||||||||
| 38 | sub latest_distribution { | ||||||||||
| 39 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
latest_distribution: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 40 | 1 | $self->_dist_for_status($self->{latest}); | |||||||||
| 41 | } | ||||||||||
| 42 | |||||||||||
| 43 | sub distribution_for_version { | ||||||||||
| 44 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
distribution_for_version: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 45 | 2 | ▶ | my $vdata = $self->info_for_version(shift) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 2 | return $self->{_pgxn}->get_distribution(@{ $vdata->[0] }{qw(dist version)}); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | sub info_for_version { | ||||||||||
| 50 | 4 | ▶ | my ($self, $version) = @_; | ||||||||
|
Subroutine
info_for_version: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 51 | 4 | $self->{versions}{$version}; | |||||||||
| 52 | } | ||||||||||
| 53 | |||||||||||
| 54 | sub _dist_for_status { | ||||||||||
| 55 | 4 | ▶ | my ($self, $status) = @_; | ||||||||
|
Subroutine
_dist_for_status: called CC=2 SCAR=6.9
| |||||||||||
| 56 | 4 | ▶ | my $vdata = $self->{$status} or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 2 | return $self->{_pgxn}->get_distribution(@{ $vdata }{qw(dist version)}); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | sub download_stable_to { | ||||||||||
| 61 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
download_stable_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 62 | 1 | $self->_download_to(shift, $self->{stable}); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | sub download_latest_to { | ||||||||||
| 66 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
download_latest_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 67 | 1 | $self->_download_to(shift, $self->latest_info); | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | sub download_testing_to { | ||||||||||
| 71 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
download_testing_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 72 | 1 | $self->_download_to(shift, $self->{testing}); | |||||||||
| 73 | } | ||||||||||
| 74 | |||||||||||
| 75 | sub download_unstable_to { | ||||||||||
| 76 | 1 | ▶ | my $self = shift; | ||||||||
|
Subroutine
download_unstable_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 77 | 1 | $self->_download_to(shift, $self->{unstable}); | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | sub download_version_to { | ||||||||||
| 81 | 2 | ▶ | my ($self, $version, $file) = @_; | ||||||||
|
Subroutine
download_version_to: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 82 | 2 | ▶ | my $info = $self->info_for_version($version) or return; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | 1 | $self->_download_to($file, $info->[0]); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | sub _download_to { | ||||||||||
| 87 | 5 | ▶ | my ($self, $file, $info) = @_; | ||||||||
|
Subroutine
_download_to: called CC=2 SCAR=6.9
| |||||||||||
| 88 | 5 | ▶ | return unless $info; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | $self->{_pgxn}->_download_to($file => { | ||||||||||
| 90 | dist => $info->{dist}, | ||||||||||
| 91 | version => $info->{version}, | ||||||||||
| 92 | 3 | }); | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 9 | 1; | |||||||||
| 96 | |||||||||||
| 97 | __END__ | ||||||||||
| 98 | |||||||||||
| 99 | =head1 Name | ||||||||||
| 100 | |||||||||||
| 101 | WWW::PGXN::Extension - Extension metadata fetched from PGXN | ||||||||||
| 102 | |||||||||||
| 103 | =head1 Synopsis | ||||||||||
| 104 | |||||||||||
| 105 | my $pgxn = WWW::PGXN->new( url => 'http://api.pgxn.org/' ); | ||||||||||
| 106 | my $ext = $pgxn->get_extension('pgTAP'); | ||||||||||
| 107 | $ext->download_stable_to('.'); | ||||||||||
| 108 | |||||||||||
| 109 | =head1 Description | ||||||||||
| 110 | |||||||||||
| 111 | This module represents PGXN extension metadata fetched from PGXN>. It is not | ||||||||||
| 112 | intended to be constructed directly, but via the L<WWW::PGXN/get_extension> | ||||||||||
| 113 | method of L<WWW::PGXN>. | ||||||||||
| 114 | |||||||||||
| 115 | =head1 Interface | ||||||||||
| 116 | |||||||||||
| 117 | =begin private | ||||||||||
| 118 | |||||||||||
| 119 | =head2 Constructor | ||||||||||
| 120 | |||||||||||
| 121 | =head3 C<new> | ||||||||||
| 122 | |||||||||||
| 123 | my $extension = WWW::PGXN::Extension->new($pgxn, $data); | ||||||||||
| 124 | |||||||||||
| 125 | Construct a new WWW::PGXN::Extension object. The first argument must be an | ||||||||||
| 126 | instance of L<WWW::PGXN> that connected to the PGXN server. The second | ||||||||||
| 127 | argument must be the data fetched. | ||||||||||
| 128 | |||||||||||
| 129 | =end private | ||||||||||
| 130 | |||||||||||
| 131 | =head2 Instance Accessors | ||||||||||
| 132 | |||||||||||
| 133 | =head3 C<name> | ||||||||||
| 134 | |||||||||||
| 135 | my $name = $extension->name; | ||||||||||
| 136 | $extension->name($name); | ||||||||||
| 137 | |||||||||||
| 138 | The name of the extension. | ||||||||||
| 139 | |||||||||||
| 140 | =head3 C<latest> | ||||||||||
| 141 | |||||||||||
| 142 | my $latest = $extension->latest; | ||||||||||
| 143 | $extension->latest($latest); | ||||||||||
| 144 | |||||||||||
| 145 | The status of the latest release. Should be one of: | ||||||||||
| 146 | |||||||||||
| 147 | =over | ||||||||||
| 148 | |||||||||||
| 149 | =item stable | ||||||||||
| 150 | |||||||||||
| 151 | =item testing | ||||||||||
| 152 | |||||||||||
| 153 | =item unstable | ||||||||||
| 154 | |||||||||||
| 155 | =back | ||||||||||
| 156 | |||||||||||
| 157 | =head2 Instance Methods | ||||||||||
| 158 | |||||||||||
| 159 | =head3 C<stable_info> | ||||||||||
| 160 | |||||||||||
| 161 | =head3 C<testing_info> | ||||||||||
| 162 | |||||||||||
| 163 | =head3 C<unstable_info> | ||||||||||
| 164 | |||||||||||
| 165 | my $stable_info = $extension->stable_info; | ||||||||||
| 166 | my $testing_info = $extension->testing_info; | ||||||||||
| 167 | my $unstable_info = $extension->unstable_info; | ||||||||||
| 168 | |||||||||||
| 169 | Returns a hash reference describing the latest version of the extension for | ||||||||||
| 170 | the named release status. The supported keys are: | ||||||||||
| 171 | |||||||||||
| 172 | =over | ||||||||||
| 173 | |||||||||||
| 174 | =item C<dist> | ||||||||||
| 175 | |||||||||||
| 176 | The name of the distribution in which the extension may be found. | ||||||||||
| 177 | |||||||||||
| 178 | =item C<version> | ||||||||||
| 179 | |||||||||||
| 180 | The version of the distribution in which the extension may be found. | ||||||||||
| 181 | |||||||||||
| 182 | =item C<abstract> | ||||||||||
| 183 | |||||||||||
| 184 | A brief description of the extension. Available only from PGXN API servers, | ||||||||||
| 185 | not mirrors. | ||||||||||
| 186 | |||||||||||
| 187 | =item C<sha1> | ||||||||||
| 188 | |||||||||||
| 189 | The SHA1 hash for the distribution archive file. | ||||||||||
| 190 | |||||||||||
| 191 | =item C<docpath> | ||||||||||
| 192 | |||||||||||
| 193 | A path to the documentation for the extension, if any. | ||||||||||
| 194 | |||||||||||
| 195 | =back | ||||||||||
| 196 | |||||||||||
| 197 | If no release has been made with the given status, an empty hash reference | ||||||||||
| 198 | will be returned. Here's an example of the structure for a distribution loaded | ||||||||||
| 199 | from an API server: | ||||||||||
| 200 | |||||||||||
| 201 | { | ||||||||||
| 202 | dist => 'pair', | ||||||||||
| 203 | version => '0.1.1', | ||||||||||
| 204 | abstract => 'A key/value pair data type', | ||||||||||
| 205 | sha1 => 'c552c961400253e852250c5d2f3def183c81adb3', | ||||||||||
| 206 | docpath => 'doc/pair', | ||||||||||
| 207 | } | ||||||||||
| 208 | |||||||||||
| 209 | =head3 C<latest_info> | ||||||||||
| 210 | |||||||||||
| 211 | my $latest_info = $extension->latest_info; | ||||||||||
| 212 | |||||||||||
| 213 | Returns a hash reference describing the latest version of the extension. | ||||||||||
| 214 | Essentially a convenience method for: | ||||||||||
| 215 | |||||||||||
| 216 | my $meth = $extension->latest . '_info'; | ||||||||||
| 217 | my $info = $extension->$meth; | ||||||||||
| 218 | |||||||||||
| 219 | =head3 C<info_for_version> | ||||||||||
| 220 | |||||||||||
| 221 | my $version_info = $extension->info_for_version; | ||||||||||
| 222 | |||||||||||
| 223 | Returns a hash reference containing the distribution information for the named | ||||||||||
| 224 | version of the extension, if it exists. The supported keys are: | ||||||||||
| 225 | |||||||||||
| 226 | =over | ||||||||||
| 227 | |||||||||||
| 228 | =item C<dist> | ||||||||||
| 229 | |||||||||||
| 230 | The name of the distribution in which the version of the extension may be | ||||||||||
| 231 | found. | ||||||||||
| 232 | |||||||||||
| 233 | =item C<version> | ||||||||||
| 234 | |||||||||||
| 235 | The version of the distribution in which the version of the extension may be | ||||||||||
| 236 | found. | ||||||||||
| 237 | |||||||||||
| 238 | =item C<date> | ||||||||||
| 239 | |||||||||||
| 240 | The release date the distribution containing the version of the extension. | ||||||||||
| 241 | Available only from PGXN API servers, not mirrors. | ||||||||||
| 242 | |||||||||||
| 243 | Returns C<undef> if no such version of the extension exists. | ||||||||||
| 244 | |||||||||||
| 245 | =back | ||||||||||
| 246 | |||||||||||
| 247 | =head3 C<stable_distribution> | ||||||||||
| 248 | |||||||||||
| 249 | =head3 C<testing_distribution> | ||||||||||
| 250 | |||||||||||
| 251 | =head3 C<unstable_distribution> | ||||||||||
| 252 | |||||||||||
| 253 | my $stable_distribution = $extension->stable_distribution; | ||||||||||
| 254 | my $testing_distribution = $extension->testing_distribution; | ||||||||||
| 255 | my $unstable_distribution = $extension->unstable_distribution; | ||||||||||
| 256 | |||||||||||
| 257 | Returns a L<WWW::PGXN::Distribution> object describing the distribution | ||||||||||
| 258 | containing the distribution with the named release status. Returns C<undef> if | ||||||||||
| 259 | no distribution contains the extension with that status. | ||||||||||
| 260 | |||||||||||
| 261 | =head3 C<latest_distribution> | ||||||||||
| 262 | |||||||||||
| 263 | Returns a L<WWW::PGXN::Distribution> object describing the distribution in | ||||||||||
| 264 | which the latest version of the extension is found. Essentially a convenience | ||||||||||
| 265 | method for: | ||||||||||
| 266 | |||||||||||
| 267 | my $meth = $extension->latest . '_distribution'; | ||||||||||
| 268 | my $dist = $extension->$meth; | ||||||||||
| 269 | |||||||||||
| 270 | =head3 C<distribution_for_version> | ||||||||||
| 271 | |||||||||||
| 272 | my $version_distribution = $extension->distribution_for_version($version); | ||||||||||
| 273 | |||||||||||
| 274 | Returns a L<WWW::PGXN::Distribution> object describing the distribution in | ||||||||||
| 275 | which the named version of the extension is found. Returns C<undef> if no such | ||||||||||
| 276 | version of the extension exists. | ||||||||||
| 277 | |||||||||||
| 278 | =head3 C<download_stable_to> | ||||||||||
| 279 | |||||||||||
| 280 | =head3 C<download_testing_to> | ||||||||||
| 281 | |||||||||||
| 282 | =head3 C<download_unstable_to> | ||||||||||
| 283 | |||||||||||
| 284 | my $stable_file = $extension->download_stable_to('/usr/src'); | ||||||||||
| 285 | my $testing_file = $extension->download_testing_to('.'); | ||||||||||
| 286 | my $unstable_file = $extension->download_unstable_to('mfile.zip'); | ||||||||||
| 287 | |||||||||||
| 288 | Downloads the distribution containing the latest version of the extension with | ||||||||||
| 289 | the named release status. Pass the name of the file to save to, or the name of | ||||||||||
| 290 | a directory. If a directory is specified, the file will be written with the | ||||||||||
| 291 | same name as it has on PGXN, such as C<pgtap-0.24.0.zip>. Either way, the name | ||||||||||
| 292 | of the file written will be returned. Regardless of the file's name, it will | ||||||||||
| 293 | always be a zip archive. | ||||||||||
| 294 | |||||||||||
| 295 | =head3 C<download_latest_to> | ||||||||||
| 296 | |||||||||||
| 297 | my $file = $extension->download_latest_to($file); | ||||||||||
| 298 | |||||||||||
| 299 | Download the distribution containing the latest version of the distribution, | ||||||||||
| 300 | regardless of its release status. Essentially a convenience method for: | ||||||||||
| 301 | |||||||||||
| 302 | my $meth = 'download_' . $extension->latest . '_to'; | ||||||||||
| 303 | my $file = $extension->$meth('.'); | ||||||||||
| 304 | |||||||||||
| 305 | =head3 C<download_version_to> | ||||||||||
| 306 | |||||||||||
| 307 | my $file = $extension->download_version_to($version, $file); | ||||||||||
| 308 | |||||||||||
| 309 | Download the distribution containing the specified version of the extension. | ||||||||||
| 310 | |||||||||||
| 311 | =head1 See Also | ||||||||||
| 312 | |||||||||||
| 313 | =over | ||||||||||
| 314 | |||||||||||
| 315 | =item * L<WWW::PGXN> | ||||||||||
| 316 | |||||||||||
| 317 | The main class to communicate with a PGXN mirror or API server. | ||||||||||
| 318 | |||||||||||
| 319 | =back | ||||||||||
| 320 | |||||||||||
| 321 | =head1 Support | ||||||||||
| 322 | |||||||||||
| 323 | This module is stored in an open L<GitHub | ||||||||||
| 324 | repository|http://github.com/theory/www-pgxn/>. Feel free to fork and | ||||||||||
| 325 | contribute! | ||||||||||
| 326 | |||||||||||
| 327 | Please file bug reports via L<GitHub | ||||||||||
| 328 | Issues|http://github.com/theory/www-pgxn/issues/> or by sending mail to | ||||||||||
| 329 | L<bug-WWW-PGXN@rt.cpan.org|mailto:bug-WWW-PGXN@rt.cpan.org>. | ||||||||||
| 330 | |||||||||||
| 331 | =head1 Author | ||||||||||
| 332 | |||||||||||
| 333 | David E. Wheeler <david@justatheory.com> | ||||||||||
| 334 | |||||||||||
| 335 | =head1 Copyright and License | ||||||||||
| 336 | |||||||||||
| 337 | Copyright (c) 2011 David E. Wheeler. Some Rights Reserved. | ||||||||||
| 338 | |||||||||||
| 339 | This module is free software; you can redistribute it and/or modify it under | ||||||||||
| 340 | the same terms as Perl itself. | ||||||||||
| 341 | |||||||||||
| 342 | =cut | ||||||||||