| 1 | # | ||||||||||||||||||||||||||||||||||||||
| 2 | # This file is part of Dist-Zilla-Plugin-ContributorsFromGit | ||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||
| 4 | # This software is Copyright (c) 2017, 2015, 2014, 2013, 2012 by Chris Weyl. | ||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||
| 6 | # This is free software, licensed under: | ||||||||||||||||||||||||||||||||||||||
| 7 | # | ||||||||||||||||||||||||||||||||||||||
| 8 | # The GNU Lesser General Public License, Version 2.1, February 1999 | ||||||||||||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||||||||||||
| 10 | package Dist::Zilla::Plugin::ContributorsFromGit; | ||||||||||||||||||||||||||||||||||||||
| 11 | 2 | our $AUTHORITY = 'cpan:RSRCHBOY'; | |||||||||||||||||||||||||||||||||||||
| 12 | # git description: 0.018-4-g702588a | ||||||||||||||||||||||||||||||||||||||
| 13 | 2 | $Dist::Zilla::Plugin::ContributorsFromGit::VERSION = '0.019'; | |||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | # ABSTRACT: Populate your 'CONTRIBUTORS' POD from the list of git authors | ||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 18 | 2 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 21 | 2 | ▶ | use MooseX::AttributeShortcuts; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | use MooseX::Types::Moose ':all'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | use Encode qw(decode_utf8); | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | use autobox::Core; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 25 | 2 | ▶ | use autobox::Junctions; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | use File::Which 'which'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | use List::AllUtils qw{ max uniq apply }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | use File::ShareDir qw/ dist_dir /; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | use YAML::Tiny; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | use Path::Class; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||
| 32 | 2 | ▶ | use autodie 'system'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | use IPC::System::Simple ( ); # explict dep for autodie system | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | use aliased 'Dist::Zilla::Stash::PodWeaver'; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | 2 | with | |||||||||||||||||||||||||||||||||||||
| 38 | 'Dist::Zilla::Role::BeforeBuild', | ||||||||||||||||||||||||||||||||||||||
| 39 | 'Dist::Zilla::Role::RegisterStash', | ||||||||||||||||||||||||||||||||||||||
| 40 | 'Dist::Zilla::Role::MetaProvider', | ||||||||||||||||||||||||||||||||||||||
| 41 | ; | ||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||
| 43 | has _contributor_list => ( | ||||||||||||||||||||||||||||||||||||||
| 44 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 45 | isa => 'ArrayRef[Str]', | ||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | builder => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Subroutine
_build__contributor_list: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 47 | 0 | my $self = shift @_; | |||||||||||||||||||||||||||||||||||||
| 48 | 0 | my @authors = $self->zilla->authors->flatten; | |||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||
| 50 | ### and get our list from git, filtering: "@authors" | ||||||||||||||||||||||||||||||||||||||
| 51 | my @contributors = uniq | ||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | map { $self->_contributor_emails->{$_} // $_ } | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$self->_contributor_emails->{$_} // $_
$self->_contributor_emails->{$_} // $_
MC/DC0%0/2
$self->_contributor_emails->{$_} // $_
$self->_contributor_emails->{$_}
$_
MC/DC0%0/2
$self->_contributor_emails->{$_} // $_
$self->_contributor_emails->{$_}
$_
Truth table0%0/3
A // B
A= $self->_contributor_emails->{$_}B= $_
Truth table0%0/3
A // B
A= $self->_contributor_emails->{$_}B= $_
| |||||||||||||||||||||||||||||||||||||||
| 53 | 0 | grep { $_ ne 'Your Name <you@example.com>' } | |||||||||||||||||||||||||||||||||||||
| 54 | 0 | grep { [ map { lc } @authors ]->none eq lc } | |||||||||||||||||||||||||||||||||||||
| 55 | 0 | map { decode_utf8($_) } | |||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | apply { chomp; s/^\s*\d+\s*// } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 57 | 0 | `git shortlog -s -e HEAD` | |||||||||||||||||||||||||||||||||||||
| 58 | ; | ||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||
| 60 | 0 | return [ sort @contributors ]; | |||||||||||||||||||||||||||||||||||||
| 61 | }, | ||||||||||||||||||||||||||||||||||||||
| 62 | 2 | ); | |||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||
| 64 | has _contributor_emails => ( | ||||||||||||||||||||||||||||||||||||||
| 65 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 66 | isa => HashRef[Str], | ||||||||||||||||||||||||||||||||||||||
| 67 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | builder => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my $mapping = YAML::Tiny | |||||||||||||||||||||||||||||||||||||
| 72 | ->read( | ||||||||||||||||||||||||||||||||||||||
| 73 | file( | ||||||||||||||||||||||||||||||||||||||
| 74 | dist_dir('Dist-Zilla-Plugin-ContributorsFromGit'), | ||||||||||||||||||||||||||||||||||||||
| 75 | 'author-emails.yaml', | ||||||||||||||||||||||||||||||||||||||
| 76 | ), | ||||||||||||||||||||||||||||||||||||||
| 77 | ) | ||||||||||||||||||||||||||||||||||||||
| 78 | ->[0] | ||||||||||||||||||||||||||||||||||||||
| 79 | ; | ||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | my $_map_it = sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my ($canonical, @alternates) = @_; | |||||||||||||||||||||||||||||||||||||
| 83 | 0 | return ( map { $_ => $canonical } @alternates ); | |||||||||||||||||||||||||||||||||||||
| 84 | 0 | }; | |||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | return { | ||||||||||||||||||||||||||||||||||||||
| 87 | 0 | map { $_map_it->($_ => $mapping->{$_}->flatten) } | |||||||||||||||||||||||||||||||||||||
| 88 | $mapping->keys->flatten | ||||||||||||||||||||||||||||||||||||||
| 89 | }; | ||||||||||||||||||||||||||||||||||||||
| 90 | }, | ||||||||||||||||||||||||||||||||||||||
| 91 | 2 | ); | |||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||
| 93 | has _stopwords => ( | ||||||||||||||||||||||||||||||||||||||
| 94 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||
| 95 | isa => ArrayRef[Str], | ||||||||||||||||||||||||||||||||||||||
| 96 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | builder => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__stopwords: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $self = shift @_; | |||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||
| 101 | # break contributor names into a stopwords-suitable list | ||||||||||||||||||||||||||||||||||||||
| 102 | my @stopwords = | ||||||||||||||||||||||||||||||||||||||
| 103 | 0 | map { (split / /) } | |||||||||||||||||||||||||||||||||||||
| 104 | 0 | map { /^(.*) <.*$/; $1 } | |||||||||||||||||||||||||||||||||||||
| 105 | $self->_contributor_list->flatten | ||||||||||||||||||||||||||||||||||||||
| 106 | ; | ||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||
| 108 | 0 | return [ uniq sort @stopwords ]; | |||||||||||||||||||||||||||||||||||||
| 109 | }, | ||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ); | |||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | sub before_build { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
before_build: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 113 | 0 | my $self = shift @_; | |||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||
| 115 | # skip if we can't find git | ||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | unless (which 'git') { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $self->log('The "git" executable has not been found'); | |||||||||||||||||||||||||||||||||||||
| 118 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||
| 121 | # XXX we should also check here that we're in a git repo, but I'm going to | ||||||||||||||||||||||||||||||||||||||
| 122 | # leave that for the git stash (when it's not vaporware) | ||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||
| 124 | ### get our stash... | ||||||||||||||||||||||||||||||||||||||
| 125 | 0 | my $stash = $self->zilla->stash_named('%PodWeaver'); | |||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | do { $stash = PodWeaver->new; $self->_register_stash('%PodWeaver', $stash) } | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 127 | unless defined $stash; | ||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||
| 129 | ### ...and config... | ||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $config = $stash->_config; | |||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||
| 132 | # helper sub to keep us from clobbering existing values, until (and if): | ||||||||||||||||||||||||||||||||||||||
| 133 | # https://github.com/rwstauner/Dist-Zilla-Role-Stash-Plugins/pull/1 | ||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | my $_append = sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||
| 135 | 0 | my ($key, @values) = @_; | |||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $i = -1; | |||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | do { $i++ } while exists $config->{$key."[$i]"}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 139 | 0 | do { $config->{$key."[$i]"} = $_; $i++ } | |||||||||||||||||||||||||||||||||||||
| 140 | 0 | for @values; | |||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 143 | 0 | }; | |||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||
| 145 | 0 | $_append->('Contributors.contributors' => $self->_contributor_list->flatten); | |||||||||||||||||||||||||||||||||||||
| 146 | 0 | $_append->('-StopWords.include' => $self->_stopwords->flatten); | |||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||
| 148 | ### $config | ||||||||||||||||||||||||||||||||||||||
| 149 | 0 | return; | |||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub metadata { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
metadata: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift @_; | |||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $list = $self->_contributor_list; | |||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return @$list ? { 'x_contributors' => $list } : {}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||
| 158 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||
| 159 | 2 | !!42; | |||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||
| 161 | __END__ | ||||||||||||||||||||||||||||||||||||||