| 1 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | package Dist::Zilla::Role::RepoFileInjector; # git description: v0.008-2-g97bfee5 | ||||||||||||||||||||||||||||
| 4 | # vim: set ts=8 sts=4 sw=4 tw=115 et : | ||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Create files outside the build directory | ||||||||||||||||||||||||||||
| 6 | # KEYWORDS: plugin distribution generate create file repository | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | our $VERSION = '0.009'; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use MooseX::Types qw(enum role_type); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use MooseX::Types::Moose qw(ArrayRef Str Bool); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Path::Tiny 0.022; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | has repo_root => ( | ||||||||||||||||||||||||||||
| 18 | is => 'ro', isa => Str, | ||||||||||||||||||||||||||||
| 19 | predicate => '_has_repo_root', | ||||||||||||||||||||||||||||
| 20 | lazy => 1, | ||||||||||||||||||||||||||||
| 21 | 3 | ▶ | default => sub { shift->zilla->root->stringify }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | 3 | ); | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 3 | has allow_overwrite => ( | |||||||||||||||||||||||||||
| 25 | is => 'ro', isa => Bool, | ||||||||||||||||||||||||||||
| 26 | default => 1, | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | has _repo_files => ( | ||||||||||||||||||||||||||||
| 30 | isa => ArrayRef[role_type('Dist::Zilla::Role::File')], | ||||||||||||||||||||||||||||
| 31 | lazy => 1, | ||||||||||||||||||||||||||||
| 32 | 4 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | 3 | traits => ['Array'], | |||||||||||||||||||||||||||
| 34 | handles => { | ||||||||||||||||||||||||||||
| 35 | __push_repo_file => 'push', | ||||||||||||||||||||||||||||
| 36 | _repo_files => 'elements', | ||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | around dump_config => sub | ||||||||||||||||||||||||||||
| 41 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 42 | 4 | my ($orig, $self) = @_; | |||||||||||||||||||||||||||
| 43 | 4 | my $config = $self->$orig; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 4 | ▶ | $config->{+__PACKAGE__} = { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 46 | version => $VERSION, | ||||||||||||||||||||||||||||
| 47 | allow_overwrite => ( $self->allow_overwrite ? 1 : 0 ), | ||||||||||||||||||||||||||||
| 48 | repo_root => ( $self->_has_repo_root ? path($self->repo_root)->stringify : '.' ), | ||||||||||||||||||||||||||||
| 49 | }; | ||||||||||||||||||||||||||||
| 50 | 4 | return $config; | |||||||||||||||||||||||||||
| 51 | 3 | }; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | sub add_repo_file | ||||||||||||||||||||||||||||
| 54 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
add_repo_file: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 55 | 4 | my ($self, $file) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 4 | my ($pkg, undef, $line) = caller; | |||||||||||||||||||||||||||
| 58 | 4 | ▶ | if ($file->can('_set_added_by')) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | { | ||||||||||||||||||||||||||||
| 60 | 4 | $file->_set_added_by(sprintf("%s (%s line %s)", $self->plugin_name, $pkg, $line)); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | else | ||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||
| 64 | # as done in Dist::Zilla::Role::FileInjector 4.300039 | ||||||||||||||||||||||||||||
| 65 | 0 | $file->meta->get_attribute('added_by')->set_value( | |||||||||||||||||||||||||||
| 66 | $file, | ||||||||||||||||||||||||||||
| 67 | sprintf("%s (%s line %s)", $self->plugin_name, $pkg, $line), | ||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 4 | $self->log_debug([ 'adding file %s', $file->name ]); | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 4 | $self->__push_repo_file($file); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub write_repo_files | ||||||||||||||||||||||||||||
| 77 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
write_repo_files: called CC=10 SCAR=23.4
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 4 | foreach my $file ($self->_repo_files) | |||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | 4 | my $filename = path($file->name); | |||||||||||||||||||||||||||
| 83 | 4 | ▶ | my $abs_filename = $filename->is_relative | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | ? path($self->repo_root)->child($file->name) | ||||||||||||||||||||||||||||
| 85 | : $file->name; | ||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 4 | ▶ | if ($abs_filename->exists and $self->allow_overwrite) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$abs_filename->exists and $self->allow_overwrite
MC/DC100%2/2
$abs_filename->exists and $self->allow_overwrite
$abs_filename->exists
$self->allow_overwrite
Truth table100%3/3
A and B
A= $abs_filename->existsB= $self->allow_overwrite
| |||||||||||||||||||||||||||||
| 88 | { | ||||||||||||||||||||||||||||
| 89 | 1 | $self->log_debug([ 'removing pre-existing %s', $abs_filename->stringify ]); | |||||||||||||||||||||||||||
| 90 | 1 | $abs_filename->remove; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 4 | ▶ | $self->log_fatal([ '%s already exists (allow_overwrite = 0)', $abs_filename->stringify ]) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | if $abs_filename->exists; | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 3 | ▶ | $self->log_debug([ 'writing out %s%s', $file->name, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | $filename->is_relative ? ' to ' . path($self->repo_root)->stringify : '' ]); | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 3 | ▶ | Carp::croak("attempted to write $filename multiple times") if $abs_filename->exists; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 3 | $abs_filename->touchpath; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | # handle dzil v4 files by assuming no (or latin1) encoding | ||||||||||||||||||||||||||||
| 102 | 3 | ▶ | my $encoded_content = $file->can('encoded_content') ? $file->encoded_content : $file->content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 3 | $abs_filename->spew_raw($encoded_content); | |||||||||||||||||||||||||||
| 105 | 3 | ▶ | chmod $file->mode, "$abs_filename" or die "couldn't chmod $abs_filename: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 3 | 1; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||