blib/lib/Dist/Zilla/Plugin/Bootstrap/ShareDir/Module.pm

filter: Statementstmt 83.0% 49 / 59 Branchbran 37.5% 3 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod n/a totaltotal 77.6% 59 / 76 CC 8 SCAR 14.5
CC
8
Cov
78%
__ANON__
12.0
bootstrap
4.0
__ANON__
3.0
CRAP 4.3
↑ Summary
1 5 ▶use 5.006; # our
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Dist::Zilla::Plugin::Bootstrap::ShareDir::Module;
6  
7 5 our $VERSION = '1.001002';
8  
9 # ABSTRACT: Use a share directory on your dist for a module during bootstrap
10  
11 5 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 5 ▶use Moose qw( with has around );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 with 'Dist::Zilla::Role::Bootstrap';
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29 5 has module_map => (
30 is => 'ro',
31 isa => 'HashRef',
32 lazy_build => 1,
33 );
34  
35 0 ▶sub _build_module_map { return {} }
Subroutine _build_module_map: not called CC=1 SCAR=6.9
36  
37 0 ▶around 'dump_config' => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
38 0 my ( $orig, $self, @args ) = @_;
39 0 my $config = $self->$orig(@args);
40 0 my $localconf = $config->{ +__PACKAGE__ } = {};
41  
42 0 ▶ if ( $self->meta->find_attribute_by_name('module_map')->has_value($self) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->meta->find_attribute_by_name("module_map")->has_value($self)) 0 0 0
43 0 $localconf->{module_map} = $self->module_map;
44 }
45 0 ▶ $localconf->{ q[$] . __PACKAGE__ . '::VERSION' } = $VERSION
Branch: 1 branch
BranchTrueFalseTotal
unless __PACKAGE__ eq ref $self 0 0 0
46 unless __PACKAGE__ eq ref $self;
47  
48 0 return $config;
49 5 };
50  
51 4 ▶around 'plugin_from_config' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
52 4 my ( $orig, $self, $name, $payload, $section ) = @_;
53  
54 4 my $special_fields = [qw( try_built fallback )];
55 4 my $module_map = { %{$payload} };
56 4 my $new = {};
57  
58 4 for my $field ( @{$special_fields} ) {
59 8 ▶ $new->{$field} = delete $module_map->{$field} if exists $module_map->{$field};
Branch: 1 branch
BranchTrueFalseTotal
if exists $module_map->{$field} 4 4 8
60 }
61 4 $new->{module_map} = $module_map;
62  
63 4 return $self->$orig( $name, $new, $section );
64 5 };
65  
66 4 ▶sub bootstrap {
Subroutine bootstrap: called CC=4 SCAR=14.0
67 4 my $self = shift;
68 4 my $root = $self->_bootstrap_root;
69  
70 4 ▶ if ( not defined $root ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $root) 0 4 4
71 0 $self->log( ['Not bootstrapping'] );
72 0 return;
73 }
74 4 my $resolved_map = {};
75  
76 4 for my $key ( keys %{ $self->module_map } ) {
77 4 require Path::Tiny;
78 4 $resolved_map->{$key} = Path::Tiny::path( $self->module_map->{$key} )->absolute($root);
79 }
80 4 require Test::File::ShareDir::Object::Module;
81 4 my $share_object = Test::File::ShareDir::Object::Module->new( modules => $resolved_map );
82 4 for my $module ( $share_object->module_names ) {
83 4 $self->log( [ 'Bootstrapped sharedir for %s -> %s', $module, $resolved_map->{$module}->relative(q[.])->stringify ] );
84 4 $self->log_debug(
85 [
86 'Installing module %s sharedir ( %s => %s )',
87 "$module",
88 $share_object->module_share_source_dir($module) . q{},
89 $share_object->module_share_target_dir($module) . q{},
90 ],
91 );
92 4 $share_object->install_module($module);
93 }
94 4 $self->_add_inc( $share_object->inc->tempdir . q{} );
95 4 $self->log_debug( [ 'Sharedir for %s installed to %s', $self->distname, $share_object->inc->module_tempdir . q{} ] );
96 4 return;
97 }
98  
99 5 __PACKAGE__->meta->make_immutable;
100 5 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
101  
102 5 1;
103  
104 __END__
↑ Summary