| 1 | 3 | ▶ | use 5.006; # our | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | package Dist::Zilla::Role::xPANResolver; | ||||||||||
| 6 | |||||||||||
| 7 | 3 | our $VERSION = 'v0.3.0'; | |||||||||
| 8 | |||||||||||
| 9 | 3 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | |||||||||
| 10 | |||||||||||
| 11 | # FILENAME: xPANResolver.pm | ||||||||||
| 12 | # CREATED: 30/10/11 14:05:14 by Kent Fredric (kentnl) <kentfredric@gmail.com> | ||||||||||
| 13 | # ABSTRACT: Tools to resolve a package to a URI from a CPAN/DARKPAN mirror. | ||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | |||||||||||
| 25 | |||||||||||
| 26 | 3 | ▶ | use Moose::Role qw( around ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | around dump_config => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||
| 29 | 0 | my ( $orig, $self, @args ) = @_; | |||||||||
| 30 | 0 | my $config = $self->$orig(@args); | |||||||||
| 31 | 0 | my $payload = $config->{ +__PACKAGE__ } = {}; | |||||||||
| 32 | |||||||||||
| 33 | ## no critic (RequireInterpolationOfMetachars) | ||||||||||
| 34 | 0 | $payload->{ q[$] . __PACKAGE__ . q[::VERSION] } = $VERSION; | |||||||||
| 35 | 0 | ▶ | $payload->{q[$App::Cache::VERSION]} = $App::Cache::VERSION if $INC{'App/Cache.pm'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | ▶ | $payload->{q[$Parse::CPAN::Packages::VERSION]} = $Parse::CPAN::Packages::VERSION if $INC{'Parse/CPAN/Packages.pm'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | 0 | ▶ | $payload->{q[$URI::VERSION]} = $URI::VERSION if $INC{'URI.pm'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | 0 | return $config; | |||||||||
| 39 | 3 | }; | |||||||||
| 40 | |||||||||||
| 41 | 3 | ▶ | no Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | |||||||||||
| 43 | 3 | my $c; | |||||||||
| 44 | |||||||||||
| 45 | 0 | ▶ | sub _cache { | ||||||||
|
Subroutine
_cache: not called CC=2 SCAR=17.9
| |||||||||||
| 46 | 0 | ▶ | return $c if defined $c; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 0 | $c = do { | |||||||||
| 48 | 0 | require App::Cache; | |||||||||
| 49 | ## no critic (ProhibitMagicNumbers) | ||||||||||
| 50 | 0 | App::Cache->new( | |||||||||
| 51 | { | ||||||||||
| 52 | ttl => 30 * 60, | ||||||||||
| 53 | application => __PACKAGE__, | ||||||||||
| 54 | }, | ||||||||||
| 55 | ); | ||||||||||
| 56 | }; | ||||||||||
| 57 | 0 | return $c; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | sub _content_for { | ||||||||
|
Subroutine
_content_for: not called CC=1 SCAR=6.9
| |||||||||||
| 61 | 0 | my ( undef, $url ) = @_; | |||||||||
| 62 | 0 | return _cache->get_url($url); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 0 | ▶ | sub _parse_for { | ||||||||
|
Subroutine
_parse_for: not called CC=1 SCAR=6.9
| |||||||||||
| 66 | 0 | my ( $self, $url ) = @_; | |||||||||
| 67 | 0 | my $cache_url = $url . '#parsed'; | |||||||||
| 68 | 0 | require Parse::CPAN::Packages; | |||||||||
| 69 | return _cache->get_code( | ||||||||||
| 70 | $cache_url, | ||||||||||
| 71 | 0 | ▶ | sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 72 | 0 | my $content = $self->_content_for($url); | |||||||||
| 73 | 0 | return Parse::CPAN::Packages->new($content); | |||||||||
| 74 | }, | ||||||||||
| 75 | 0 | ); | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 0 | ▶ | sub _resolver_for { | ||||||||
|
Subroutine
_resolver_for: not called CC=1 SCAR=6.9
| |||||||||||
| 79 | 0 | my ( $self, $baseurl ) = @_; | |||||||||
| 80 | 0 | require URI; | |||||||||
| 81 | 0 | my $path = URI->new('modules/02packages.details.txt.gz'); | |||||||||
| 82 | 0 | my $absurl = $path->abs($baseurl)->as_string; | |||||||||
| 83 | 0 | return $self->_parse_for($absurl); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | sub resolve_module { | ||||||||
|
Subroutine
resolve_module: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 87 | 0 | my ( $self, $baseurl, $module ) = @_; | |||||||||
| 88 | 0 | my $p = $self->_resolver_for($baseurl)->package($module); | |||||||||
| 89 | 0 | my $d = $p->distribution(); | |||||||||
| 90 | 0 | require URI; | |||||||||
| 91 | 0 | my $modroot = URI->new('authors/id/')->abs( URI->new($baseurl) ); | |||||||||
| 92 | 0 | my $modpath = URI->new( $d->prefix )->abs($modroot); | |||||||||
| 93 | 0 | return $modpath->as_string; | |||||||||
| 94 | } | ||||||||||
| 95 | |||||||||||
| 96 | 3 | 1; | |||||||||
| 97 | |||||||||||
| 98 | __END__ | ||||||||||