| 1 | 6 | ▶ | use 5.14.0; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | package Dist::Iller::Plugin; | ||||||||||||||
| 6 | |||||||||||||||
| 7 | 6 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||
| 8 | # ABSTRACT: Handle a Dist::Zilla/Pod::Weaver plugin | ||||||||||||||
| 9 | 6 | our $VERSION = '0.1411'; | |||||||||||||
| 10 | |||||||||||||||
| 11 | 6 | ▶ | use Dist::Iller::Elk; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 6 | ▶ | use Types::Standard qw/Str Enum HashRef/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 6 | ▶ | use List::MoreUtils qw/uniq/; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | 6 | ▶ | use MooseX::StrictConstructor; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 6 | ▶ | use Dist::Iller::Prereq; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | 6 | with qw/ | |||||||||||||
| 18 | Dist::Iller::Role::HasPrereqs | ||||||||||||||
| 19 | /; | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 6 | has plugin_name => ( | |||||||||||||
| 22 | is => 'ro', | ||||||||||||||
| 23 | isa => Str, | ||||||||||||||
| 24 | ); | ||||||||||||||
| 25 | 6 | has base => ( | |||||||||||||
| 26 | is => 'ro', | ||||||||||||||
| 27 | isa => Str, | ||||||||||||||
| 28 | predicate => 1, | ||||||||||||||
| 29 | ); | ||||||||||||||
| 30 | 6 | has in => ( | |||||||||||||
| 31 | is => 'rw', | ||||||||||||||
| 32 | isa => Enum[qw/Plugin PluginBundle Section Elemental/], | ||||||||||||||
| 33 | default => 'Plugin', | ||||||||||||||
| 34 | ); | ||||||||||||||
| 35 | 6 | has version => ( | |||||||||||||
| 36 | is => 'rw', | ||||||||||||||
| 37 | isa => Str, | ||||||||||||||
| 38 | default => '0', | ||||||||||||||
| 39 | ); | ||||||||||||||
| 40 | 6 | has documentation => ( | |||||||||||||
| 41 | is => 'ro', | ||||||||||||||
| 42 | isa => Str, | ||||||||||||||
| 43 | predicate => 1, | ||||||||||||||
| 44 | ); | ||||||||||||||
| 45 | 6 | has parameters => ( | |||||||||||||
| 46 | is => 'ro', | ||||||||||||||
| 47 | isa => HashRef, | ||||||||||||||
| 48 | traits => [qw/Hash/], | ||||||||||||||
| 49 | handles => { | ||||||||||||||
| 50 | set_parameter => 'set', | ||||||||||||||
| 51 | get_parameter => 'get', | ||||||||||||||
| 52 | parameter_keys => 'keys', | ||||||||||||||
| 53 | delete_parameter => 'delete', | ||||||||||||||
| 54 | parameters_kv => 'kv', | ||||||||||||||
| 55 | }, | ||||||||||||||
| 56 | ); | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 106 | ▶ | around BUILDARGS => sub { | ||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||
| 59 | 106 | my $next = shift; | |||||||||||||
| 60 | 106 | my $self = shift; | |||||||||||||
| 61 | 106 | ▶ | my $args = ref $_[0] eq 'HASH' ? shift : { @_ }; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 62 | |||||||||||||||
| 63 | 106 | ▶ | if(exists $args->{'prereqs'}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | 3 | my $prereqs = []; | |||||||||||||
| 65 | |||||||||||||||
| 66 | 3 | for my $prereq (@{ $args->{'prereqs'} }) { | |||||||||||||
| 67 | 5 | my($phase, $relation) = split /_/ => (keys %{ $prereq })[0]; | |||||||||||||
| 68 | 5 | my($module, $version) = split / / => (values %{ $prereq })[0]; | |||||||||||||
| 69 | 5 | ▶ | $version ||= 0; | ||||||||||||
|
Condition100%2/2
$version ||= 0
MC/DC100%1/1
$version ||= 0
$version
Truth table100%2/2
A
A= $version
| |||||||||||||||
| 70 | |||||||||||||||
| 71 | 5 | push @{ $prereqs } => Dist::Iller::Prereq->new( | |||||||||||||
| 72 | phase => $phase, | ||||||||||||||
| 73 | relation => $relation, | ||||||||||||||
| 74 | module => $module, | ||||||||||||||
| 75 | version => $version, | ||||||||||||||
| 76 | ); | ||||||||||||||
| 77 | } | ||||||||||||||
| 78 | 3 | $args->{'prereqs'} = $prereqs; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 106 | $self->$next($args); | |||||||||||||
| 82 | 6 | }; | |||||||||||||
| 83 | |||||||||||||||
| 84 | 1 | ▶ | sub merge_with { | ||||||||||||
|
Subroutine
merge_with: called CC=5 SCAR=17.2
Pod
undocumented
| |||||||||||||||
| 85 | 1 | my $self = shift; | |||||||||||||
| 86 | 1 | my $other_plugin = shift; | |||||||||||||
| 87 | |||||||||||||||
| 88 | 1 | foreach my $param ($other_plugin->parameter_keys) { | |||||||||||||
| 89 | 2 | ▶ | if($self->get_parameter($param)) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 90 | 2 | ▶ | if(ref $other_plugin->get_parameter($param) eq 'ARRAY') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 91 | 1 | ▶ | if(ref $self->get_parameter($param) eq 'ARRAY') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 92 | 1 | my $new_param_data = [ uniq @{ $self->get_parameter($param) }, @{ $other_plugin->get_parameter($param) } ]; | |||||||||||||
| 93 | 1 | $self->set_parameter($param, $new_param_data); | |||||||||||||
| 94 | } | ||||||||||||||
| 95 | else { | ||||||||||||||
| 96 | 0 | my $new_param_data = [ uniq ($self->get_parameter($param)), @{ $other_plugin->get_parameter($param) } ]; | |||||||||||||
| 97 | 0 | $self->set_parameter($param, $new_param_data); | |||||||||||||
| 98 | } | ||||||||||||||
| 99 | } | ||||||||||||||
| 100 | else { | ||||||||||||||
| 101 | 1 | $self->set_parameter($param, $other_plugin->get_parameter($param)); | |||||||||||||
| 102 | } | ||||||||||||||
| 103 | } | ||||||||||||||
| 104 | else { | ||||||||||||||
| 105 | 0 | $self->set_parameter($param, $other_plugin->get_parameter($param)); | |||||||||||||
| 106 | } | ||||||||||||||
| 107 | } | ||||||||||||||
| 108 | } | ||||||||||||||
| 109 | |||||||||||||||
| 110 | 71 | ▶ | sub to_string { | ||||||||||||
|
Subroutine
to_string: called CC=10 SCAR=23.4
Pod
undocumented
| |||||||||||||||
| 111 | 71 | my $self = shift; | |||||||||||||
| 112 | 71 | my %options = @_; | |||||||||||||
| 113 | |||||||||||||||
| 114 | 71 | ▶ | my @strings = $self->has_base ? (sprintf '[%s / %s]' => $self->base, $self->plugin_name) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 115 | : (sprintf '[%s]' => $self->plugin_name) | ||||||||||||||
| 116 | ; | ||||||||||||||
| 117 | |||||||||||||||
| 118 | 71 | foreach my $parameter (sort $self->parameter_keys) { | |||||||||||||
| 119 | 91 | ▶ | next if $parameter =~ m{^\+}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 120 | 89 | my $value = $self->get_parameter($parameter); | |||||||||||||
| 121 | |||||||||||||||
| 122 | 89 | ▶ | if(ref $value eq 'ARRAY') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 123 | 13 | foreach my $val (@$value) { | |||||||||||||
| 124 | 14 | ▶ | push @strings => sprintf '%s =%s%s', $parameter, defined $val ? ' ' : '', defined $val ? $val : ''; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 125 | } | ||||||||||||||
| 126 | } | ||||||||||||||
| 127 | else { | ||||||||||||||
| 128 | 76 | ▶ | push @strings => sprintf '%s =%s%s', $parameter, defined $value ? ' ' : '', defined $value ? $value : ''; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 129 | } | ||||||||||||||
| 130 | } | ||||||||||||||
| 131 | |||||||||||||||
| 132 | 71 | return join "\n" => @strings; | |||||||||||||
| 133 | } | ||||||||||||||
| 134 | |||||||||||||||
| 135 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 136 | |||||||||||||||
| 137 | 6 | 1; | |||||||||||||
| 138 | |||||||||||||||
| 139 | __END__ | ||||||||||||||