| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 2 |  |  | 2 |  | 415 | use 5.006;    # our | 
|  | 2 |  |  |  |  | 5 |  | 
| 2 | 2 |  |  | 2 |  | 8 | use strict; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 45 |  | 
| 3 | 2 |  |  | 2 |  | 6 | use warnings; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 138 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | package Dist::Zilla::ExternalPrereq; | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = 'v0.3.0'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | # FILENAME: ExternalPrereq.pm | 
| 12 |  |  |  |  |  |  | # CREATED: 30/10/11 10:07:40 by Kent Fredric (kentnl) <kentfredric@gmail.com> | 
| 13 |  |  |  |  |  |  | # ABSTRACT: A representation of an externalised prerequisite | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 2 |  |  | 2 |  | 447 | use Moose qw( with has ); | 
|  | 2 |  |  |  |  | 282238 |  | 
|  | 2 |  |  |  |  | 13 |  | 
| 29 |  |  |  |  |  |  | with 'Dist::Zilla::Role::Plugin', 'Dist::Zilla::Role::xPANResolver'; | 
| 30 | 2 |  |  | 2 |  | 7620 | use Module::Runtime qw( require_module ); | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 9 |  | 
| 31 | 2 |  |  | 2 |  | 76 | use Try::Tiny qw( try catch ); | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 123 |  | 
| 32 | 2 |  |  | 2 |  | 1056 | use Path::ScanINC; | 
|  | 2 |  |  |  |  | 15542 |  | 
|  | 2 |  |  |  |  | 133 |  | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | has 'name'    => ( isa => 'Str', required => 1, is => 'rw' ); | 
| 35 |  |  |  |  |  |  | has 'baseurl' => ( isa => 'Str', required => 1, is => 'rw' ); | 
| 36 |  |  |  |  |  |  | has '_uri'    => ( | 
| 37 |  |  |  |  |  |  | isa       => 'Str', | 
| 38 |  |  |  |  |  |  | required  => 0, | 
| 39 |  |  |  |  |  |  | is        => 'rw', | 
| 40 |  |  |  |  |  |  | predicate => '_has_uri', | 
| 41 |  |  |  |  |  |  | init_arg  => 'uri', | 
| 42 |  |  |  |  |  |  | ); | 
| 43 |  |  |  |  |  |  | has 'uri' => ( | 
| 44 |  |  |  |  |  |  | isa        => 'Str', | 
| 45 |  |  |  |  |  |  | required   => 1, | 
| 46 |  |  |  |  |  |  | is         => 'rw', | 
| 47 |  |  |  |  |  |  | lazy_build => 1, | 
| 48 |  |  |  |  |  |  | init_arg   => undef, | 
| 49 |  |  |  |  |  |  | ); | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | has 'minversion' => ( | 
| 52 |  |  |  |  |  |  | isa       => 'Str', | 
| 53 |  |  |  |  |  |  | required  => undef, | 
| 54 |  |  |  |  |  |  | is        => 'rw', | 
| 55 |  |  |  |  |  |  | predicate => 'has_minversion', | 
| 56 |  |  |  |  |  |  | ); | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 2 |  |  | 2 |  | 10 | no Moose; | 
|  | 2 |  |  |  |  | 2 |  | 
|  | 2 |  |  |  |  | 11 |  | 
| 59 |  |  |  |  |  |  | __PACKAGE__->meta->make_immutable; | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | sub is_satisfied { | 
| 70 | 0 |  |  | 0 | 1 |  | my ($self) = shift; | 
| 71 |  |  |  |  |  |  | # Fence the Perl logic first to see if require is going to load a file | 
| 72 | 0 |  |  |  |  |  | my (@pmname) = split qr/::|'/xs, $self->name; | 
| 73 | 0 |  |  |  |  |  | $pmname[-1] .= '.pm'; | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 0 | 0 | 0 |  |  |  | return unless $INC{ join q{/}, @pmname } or defined Path::ScanINC->new()->first_file(@pmname); | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | # If Perl would load the file, do so, and propagate failures. | 
| 78 | 0 |  |  |  |  |  | require_module( $self->name ); | 
| 79 |  |  |  |  |  |  |  | 
| 80 | 0 | 0 |  |  |  |  | return 1 unless $self->has_minversion; | 
| 81 | 0 |  |  |  |  |  | my $satisfied = 1; | 
| 82 |  |  |  |  |  |  | try { | 
| 83 | 0 |  |  | 0 |  |  | $self->name->VERSION( $self->minversion ); | 
| 84 | 0 |  |  |  |  |  | 1; | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  | catch { | 
| 87 |  |  |  |  |  |  | ## no critic (RegularExpressions) | 
| 88 | 0 | 0 |  | 0 |  |  | if ( $_ !~ /^.*version.*required.*this is only version.*$/m ) { | 
| 89 |  |  |  |  |  |  | ## no critic ( RequireCarping ) | 
| 90 | 0 |  |  |  |  |  | die $_; | 
| 91 |  |  |  |  |  |  | } | 
| 92 | 0 |  |  |  |  |  | $satisfied = undef; | 
| 93 | 0 |  |  |  |  |  | }; | 
| 94 | 0 | 0 |  |  |  |  | return 1 if $satisfied; | 
| 95 | 0 |  |  |  |  |  | return; | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | sub _build_uri { | 
| 99 | 0 |  |  | 0 |  |  | my ($self) = @_; | 
| 100 | 0 | 0 |  |  |  |  | if ( $self->_has_uri ) { | 
| 101 | 0 |  |  |  |  |  | require URI; | 
| 102 | 0 |  |  |  |  |  | my $baseuri = URI->new( $self->baseurl ); | 
| 103 | 0 |  |  |  |  |  | return URI->new( $self->_uri )->abs($baseuri)->as_string; | 
| 104 |  |  |  |  |  |  | } | 
| 105 | 0 |  |  |  |  |  | return $self->resolve_module( $self->baseurl, $self->name ); | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | } | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | 1; | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | __END__ | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | =pod | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | =encoding UTF-8 | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =head1 NAME | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | Dist::Zilla::ExternalPrereq - A representation of an externalised prerequisite | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =head1 VERSION | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | version v0.3.0 | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =head1 METHODS | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | =head2 is_satisfied | 
| 128 |  |  |  |  |  |  |  | 
| 129 |  |  |  |  |  |  | $dep->is_satisfied | 
| 130 |  |  |  |  |  |  |  | 
| 131 |  |  |  |  |  |  | Reports if the dependency looks like its installed. | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =begin MetaPOD::JSON v1.1.0 | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | { | 
| 136 |  |  |  |  |  |  | "namespace":"Dist::Zilla::ExternalPrereq", | 
| 137 |  |  |  |  |  |  | "interface":"class", | 
| 138 |  |  |  |  |  |  | "inherits":"Moose::Object", | 
| 139 |  |  |  |  |  |  | "does":["Dist::Zilla::Role::Plugin","Dist::Zilla::Role::xPANResolver"] | 
| 140 |  |  |  |  |  |  | } | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  |  | 
| 143 |  |  |  |  |  |  | =end MetaPOD::JSON | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =head1 AUTHOR | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | Kent Fredric <kentnl@cpan.org> | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | This software is copyright (c) 2017 by Kent Fredric <kentnl@cpan.org>. | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 154 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | =cut |