Dist/Dzpl.pm

filter: Statementstmt 30.8% 37 / 120 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 63.1% 12 / 19 Podpod 0.0% 0 / 5 totaltotal 24.0% 49 / 204 CC 27 SCAR 38.0
CC
27
Cov
22%
from_file
110.0
plugin
72.0
run
30.0
CRAP 44.5
↑ Summary Dist/Dzpl/Parser.pm »
1 package Dist::Dzpl;
2 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 $Dist::Dzpl::VERSION = '0.0020';
4 }
5 # ABSTRACT: An alternative configuration format (.pl) and invoker for Dist::Zilla
6  
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 # You can actually interact with Dist::Zilla from within your configuration .pl, allowing you to easily tweak your Zilla specification on the fly
12  
13 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use Dist::Dzpl::Parser;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use Dist::Zilla::Chrome::Term;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Dist::Zilla::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Class::MOP;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Moose::Autobox;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 has zilla => qw/ is ro required 1 isa Dist::Zilla /;
24  
25 0 ▶sub from_file {
Subroutine from_file: not called CC=10 SCAR=47.0
Pod undocumented
26 0 my $self = shift;
27 0 my $file = shift;
28 0 ▶ $file = './' unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 0 0
29  
30 0 my $source;
31 0 ▶ if ( -f $file ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $file) { } 0 0 0
elsif (-d $file) { } 0 0 0
32 0 $source = $file;
33 }
34 elsif ( -d $file ) {
35 0 my @try = qw/ dzpl dz.pl dist.pl /;
36 0 for ( map { "$file/$_" } @try ) {
37 0 ▶ -e $_ and ( $source = $_ ) and last;
Branch: 1 branch
BranchTrueFalseTotal
-e $_ and $source = $_ and last 0 0 0
Condition0%0/3
-e $_ and $source = $_
!ll&&!rl&&r
000
MC/DC0%0/2
-e $_ and $source = $_
-e $_ $source = $_
Truth table0%0/3
A and B
A= -e $_B= $source = $_
ABresult
0X0
100
111
38 }
39 0 ▶ croak "Could not find ", join( ' or ', map { "\"$_\"" } @try ), " in $file" unless $source;
Branch: 1 branch
BranchTrueFalseTotal
unless $source 0 0 0
40 }
41 else {
42 0 croak "Missing file";
43 }
44 0 ▶ croak "Could not read \"$source\"" unless -r $source;
Branch: 1 branch
BranchTrueFalseTotal
unless -r $source 0 0 0
45  
46 0 my $dzpl = $self->_from_file_sandbox( $source );
47 0 ▶ die "Error while loading $source: $@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
48 0 return $dzpl;
49 }
50  
51 0 ▶sub _from_file_sandbox {
Subroutine _from_file_sandbox: not called CC=1 SCAR=6.9
52 0 my $self = shift;
53 0 my $file = shift;
54  
55 0 my $package = $file;
56 0 $package =~ s/([^A-Za-z0-9_])/sprintf("_%2x", unpack("C", $1))/eg;
57  
58 0 return eval sprintf <<'_END_', $package;
59 package Dist::Dzpl::Sandbox::%s;
60 {
61 require Dzpl;
62 do $file;
63 Dzpl->dzpl_from_package( __PACKAGE__ ) or die $@;
64 }
65 _END_
66 }
67  
68 1 ▶sub from_arguments {
Subroutine from_arguments: called CC=1 SCAR=0.0
Pod undocumented
69 1 my $self = shift;
70 1 my $zilla = Dist::Dzpl::Parser->parse( @_ );
71 1 return __PACKAGE__->new( zilla => $zilla );
72 }
73  
74 0 ▶sub run {
Subroutine run: not called CC=5 SCAR=34.0
Pod undocumented
75 0 my $self = shift;
76 0 my @arguments = @_;
77  
78 0 my $zilla = $self->zilla;
79 # TODO This should only be run once...
80 0 $zilla->_setup_default_plugins;
81  
82 0 ▶ return unless @arguments;
Branch: 1 branch
BranchTrueFalseTotal
unless @arguments 0 0 0
83  
84 0 my $do = shift @arguments;
85  
86 0 ▶ if ( $do eq 'dzil' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do eq 'dzil') { } 0 0 0
87 0 require Dist::Zilla::App;
88 0 my $app = Dist::Zilla::App->new;
89 0 $app->{__chrome__} = $zilla->chrome;
90 0 $app->{__PACKAGE__}{zilla} = $zilla; # Cover case 1...
91 0 $app->{'Dist::Zilla::App'}{zilla} = $zilla; # ...and case 2
92 {
93 0 local @ARGV = @arguments;
94 0 $app->run;
95 }
96 }
97 else {
98 0 ▶ die "Dist::Zilla cannot do \"$do\"" unless $zilla->can( $do );
Branch: 1 branch
BranchTrueFalseTotal
unless $zilla->can($do) 0 0 0
99 0 ▶ warn "Dropping arguments [@arguments]" if @arguments;
Branch: 1 branch
BranchTrueFalseTotal
if @arguments 0 0 0
100 0 return $zilla->$do;
101 }
102 }
103  
104 0 ▶sub _include_plugin_bundle {
Subroutine _include_plugin_bundle: not called CC=4 SCAR=30.0
105 0 my $self = shift;
106 0 my $name = shift;
107 0 my $package = shift;
108 0 my $payload = shift;
109 0 my $filter = shift;
110  
111 0 Class::MOP::load_class( $package );
112  
113 0 my @bundle = $package->bundle_config({
114 name => $name,
115 zilla => $self->zilla,
116 payload => $payload,
117 });
118  
119 0 for my $plugin ( @bundle ) {
120 0 my ( $name, $package, $payload ) = @$plugin;
121 0 ▶ next if $filter && $package =~ $filter;
Branch: 1 branch
BranchTrueFalseTotal
if $filter and $package =~ /$filter/ 0 0 0
Condition0%0/3
$filter and $package =~ /$filter/
!ll&&!rl&&r
000
MC/DC0%0/2
$filter and $package =~ /$filter/
$filter $package =~ /$filter/
Truth table0%0/3
A and B
A= $filterB= $package =~ /$filter/
ABresult
0X0
100
111
122 0 $self->_include_plugin( $name, $package, $payload );
123 }
124 }
125  
126 0 ▶sub _include_plugin {
Subroutine _include_plugin: not called CC=4 SCAR=30.0
127 0 my $self = shift;
128 0 my $name = shift;
129 0 my $package = shift;
130 0 my $payload = shift;
131  
132 0 Class::MOP::load_class( $package );
133  
134 0 my @arguments;
135 0 ▶ if ( ref $payload eq 'HASH' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (ref $payload eq 'HASH') { } 0 0 0
elsif (ref $payload eq 'ARRAY') { } 0 0 0
elsif (defined $payload) { } 0 0 0
136 0 push @arguments, payload => $payload;
137 }
138 elsif ( ref $payload eq 'ARRAY' ) {
139 0 push @arguments, @$payload;
140 }
141 elsif ( defined $payload ) {
142 0 die "Invalid payload ($payload)";
143 }
144  
145 0 $self->zilla->plugins->push( $package->new(
146 plugin_name => $name,
147 zilla => $self->zilla,
148 @arguments,
149 ) );
150 }
151  
152 0 ▶sub plugin {
Subroutine plugin: not called CC=8 SCAR=42.8
Pod undocumented
153 0 my $self = shift;
154
155 0 ▶ while( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
156 0 my $name_package = shift;
157 0 my ($package, $name) = $name_package =~ m{\A\s*(?:([^/\s]+)\s*/\s*)?(\S+)\z};
158 0 ▶ $package = $name unless defined $package and length $package;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package and length $package 0 0 0
Condition0%0/3
defined $package and length $package
!ll&&!rl&&r
000
MC/DC0%0/2
defined $package and length $package
defined $package length $package
Truth table0%0/3
A and B
A= defined $packageB= length $package
ABresult
0X0
100
111
159 0 $package = Dist::Zilla::Util->expand_config_package_name( $package );
160 0 Class::MOP::load_class( $package );
161 0 my $includer = '_include_plugin';
162 0 my $payload = {};
163 0 ▶ $payload = shift if ref $_[0] eq 'HASH' || ref $_[0] eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" or ref $_[0] eq "ARRAY" 0 0 0
Condition0%0/3
ref $_[0] eq "HASH" or ref $_[0] eq "ARRAY"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $_[0] eq "HASH" or ref $_[0] eq "ARRAY"
ref $_[0] eq "HASH" ref $_[0] eq "ARRAY"
Truth table0%0/3
A or B
A= ref $_[0] eq "HASH"B= ref $_[0] eq "ARRAY"
ABresult
1X1
011
000
164 0 my @arguments = ( $name, $package, $payload );
165 0 ▶ if ( $package->does( 'Dist::Zilla::Role::PluginBundle' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($package->does("Dist::Zilla::Role::PluginBundle")) 0 0 0
166 0 $includer = '_include_plugin_bundle';
167 0 ▶ my $filter = shift if ref $_[0] eq 'Regexp';
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "Regexp" 0 0 0
168 0 push @arguments, $filter;
169 }
170 0 $self->$includer( @arguments );
171 }
172  
173 }
174  
175 0 ▶sub prune {
Subroutine prune: not called CC=1 SCAR=6.9
Pod undocumented
176 0 my $self = shift;
177 0 my $pruner = shift;
178  
179 0 require Dist::Dzpl::Plugin::Prune;
180 0 $self->zilla->plugins->push( Dist::Dzpl::Plugin::Prune->new(
181 plugin_name => 'Dist::Dzpl::Plugin::Prune',
182 payload => {},
183 zilla => $self->zilla,
184 pruner => $pruner,
185 ) );
186 }
187  
188 1 __PACKAGE__->meta->make_immutable;
189 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
190 1 1;
191  
192 __END__
↑ Summary Dist/Dzpl/Parser.pm »