Plugin/Prereqs/DarkPAN.pm

filter: Statementstmt 74.7% 74 / 99 Branchbran 29.1% 7 / 24 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 10 / 14 Podpod 50.0% 1 / 2 totaltotal 66.1% 92 / 139 CC 17 SCAR 21.0
CC
17
Cov
66%
_add_attribute
30.0
BUILDARGS
7.3
register_external_prereqs
6.0
CRAP 8.2
« ExternalPrereq.pm ↑ Summary Role/xPANResolver.pm »
1 2 ▶use 5.006; # our
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Dist::Zilla::Plugin::Prereqs::DarkPAN;
6  
7 2 our $VERSION = 'v0.3.0';
8  
9 # ABSTRACT: Depend on things from arbitrary places-not-CPAN
10  
11 2 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 2 ▶use Moose qw( with has around );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 with 'Dist::Zilla::Role::PrereqSource::External';
15  
16 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31 2 has prereq_phase => (
32 is => 'ro',
33 isa => 'Str',
34 lazy => 1,
35 init_arg => undef,
36 default => 'runtime',
37 );
38  
39 2 has prereq_type => (
40 is => 'ro',
41 isa => 'Str',
42 lazy => 1,
43 init_arg => undef,
44 default => 'requires',
45 );
46  
47 # For full phase control, use above commented code.
48  
49 0 ▶has _deps => ( is => 'ro', isa => 'HashRef', default => sub { {} }, );
Subroutine __ANON__: not called CC=1 SCAR=1.2
50 0 ▶has _raw_deps => ( is => 'ro', isa => 'HashRef', default => sub { {} }, );
Subroutine __ANON__: not called CC=1 SCAR=1.2
51  
52 1 ▶around 'dump_config' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
53 1 my ( $orig, $self, @args ) = @_;
54 1 my $config = $self->$orig(@args);
55 1 my $localconf = $config->{ +__PACKAGE__ } = {};
56  
57 1 $localconf->{prereq_phase} = $self->prereq_phase;
58 1 $localconf->{prereq_type} = $self->prereq_type;
59 1 $localconf->{_raw_deps} = $self->_raw_deps;
60  
61 1 ▶ $localconf->{ q[$] . __PACKAGE__ . q[::VERSION] } = $VERSION
Branch: 1 branch
BranchTrueFalseTotal
unless __PACKAGE__ eq ref $self 0 1 1
62 unless __PACKAGE__ eq ref $self;
63 1 return $config;
64 2 };
65  
66 2 __PACKAGE__->meta->make_immutable;
67 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
68  
69 1 ▶sub _add_dep {
Subroutine _add_dep: called CC=3 SCAR=11.1
70 1 my ( undef, $stash, $args ) = @_;
71 1 ▶ $stash->{deps} = {} unless exists $stash->{deps};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $stash->{"deps"} 0 1 1
72 1 my $ds = $stash->{deps};
73 1 my $logger = $stash->{logger};
74  
75 1 my $key = $args->{key};
76 1 my $value = $args->{value};
77  
78 # TODO perhaps have support for multiple URLs with either some
79 # fallback strategy or round-robbin or random-source support.
80 # Not a priority atm.
81 return $logger->log_fatal( [ 'tried to define base uri for \'%s\' more than once.', $key ] )
82 1 ▶ if exists $ds->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $ds->{$key} 0 1 1
83  
84 1 return ( $ds->{$key} = $value );
85  
86 }
87  
88 0 ▶sub _add_attribute {
Subroutine _add_attribute: not called CC=5 SCAR=34.0
89 0 my ( undef, $stash, $args ) = @_;
90  
91 0 ▶ $stash->{attributes} = {} unless exists $stash->{attributes};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $stash->{"attributes"} 0 0 0
92  
93 0 my $attributes = $stash->{attributes};
94 0 my $logger = $stash->{logger};
95  
96 0 my $key = $args->{key};
97 0 my $attribute = $args->{attribute};
98 0 my $value = $args->{value};
99  
100 0 my $supported_attrs = { map { $_ => 1 } qw( minversion uri ) };
101  
102 return $logger->log_fatal( [ 'Attribute \'%s\' for key \'%s\' not supported.', $attribute, $key, ], )
103 0 ▶ if not exists $supported_attrs->{$attribute};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $supported_attrs->{$attribute} 0 0 0
104  
105 0 ▶ $attributes->{$key} = {} unless exists $attributes->{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attributes->{$key} 0 0 0
106  
107 return $logger->log_fatal( [ 'tried to set attribute \'%s\' for %s more than once.', $attribute, $key, ] )
108 0 ▶ if exists $attributes->{$key}->{$attribute};
Branch: 1 branch
BranchTrueFalseTotal
if exists $attributes->{$key}{$attribute} 0 0 0
109  
110 0 return ( $attributes->{$key}->{$attribute} = $value );
111  
112 }
113  
114 1 ▶sub _collect_data {
Subroutine _collect_data: called CC=3 SCAR=13.0
115 1 my ( $class, $stash, $key, $value ) = @_;
116  
117 1 my $logger = $stash->{logger};
118  
119 # Parameters
120 # -phase
121 # -type
122 # as supported by Prereqs are not supported here ( at least, not yet )
123 1 ▶ return $logger->log_fatal('dash ( - ) prefixed parameters are presently not supported.')
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /\A-/msx 0 1 1
124 if $key =~ /\A-/msx;
125  
126 1 ▶ if ( $key =~ /\A([^.]+)[.](.*\z)/msx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key =~ /\A([^.]+)[.](.*\z)/msx) 0 1 1
127  
128 # Foo::Bar.minversion
129 0 my $key_name = "$1";
130 0 my $key_attribute = "$2";
131 0 return $class->_add_attribute(
132 $stash,
133 {
134 key => $key_name,
135 attribute => $key_attribute,
136 value => $value,
137 },
138 );
139 }
140  
141 1 return $class->_add_dep( $stash, { key => $key, value => $value } );
142 }
143  
144 1 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=7 SCAR=19.8
Pod documented
145 1 my ( $class, @args ) = @_;
146 1 my %config;
147 1 ▶ if ( ref $args[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args[0]) { } 1 0 1
148 1 %config = %{ $args[0] };
149 1 shift @args;
150 }
151 else {
152 0 %config = @args;
153 }
154  
155 1 my $zilla = delete $config{zilla};
156 1 my $name = delete $config{plugin_name};
157 1 my $_deps = {};
158  
159 1 my $zilla_logger = $zilla->chrome->logger;
160 1 my $logger = $zilla_logger->proxy( { proxy_prefix => '[' . $name . ']', } );
161  
162 1 my $deps = {};
163 1 my $attributes = {};
164  
165 1 for my $key ( keys %config ) {
166 1 $class->_collect_data( { logger => $logger, deps => $deps, attributes => $attributes, }, $key, $config{$key} );
167 }
168 1 for my $dep ( keys %{$attributes} ) {
169 $logger->log_fatal( [ '[%s] Attributes specified for dependency \'%s\', which is not defined', $name, $dep ] )
170 0 ▶ unless exists $deps->{$dep};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $deps->{$dep} 0 0 0
171 }
172 1 for my $dep ( keys %{$deps} ) {
173 1 require Dist::Zilla::ExternalPrereq;
174 1 my $edep = $attributes->{$dep};
175 1 ▶ $edep = {} unless defined $edep;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $edep 1 0 1
176  
177 my $instance = Dist::Zilla::ExternalPrereq->new(
178 name => $dep,
179 plugin_name => $name . '{ExternalPrereq: dep on=\'' . $dep . '\'}',
180 zilla => $zilla,
181 baseurl => $deps->{$dep},
182  
183 1 %{$edep},
184 );
185 1 $_deps->{$dep} = $instance;
186 }
187 return {
188 1 zilla => $zilla,
189 plugin_name => $name,
190 _deps => $_deps,
191 _raw_deps => $deps,
192 logger => $logger,
193 };
194  
195 }
196  
197  
198  
199  
200  
201 0 ▶sub register_external_prereqs {
Subroutine register_external_prereqs: not called CC=2 SCAR=17.9
Pod undocumented
202 0 my ( $self, $registersub ) = @_;
203  
204 0 for my $dep ( keys %{ $self->_deps } ) {
205 $registersub->(
206 {
207 type => $self->prereq_type,
208 phase => $self->prereq_phase,
209 },
210 0 $self->_deps->{$dep},
211 );
212 }
213 0 return;
214 }
215  
216 2 1;
217  
218 __END__
« ExternalPrereq.pm ↑ Summary Role/xPANResolver.pm »