« blib/lib/Dist/Zilla/Plugin/Author/Plicease/PkgVersionBlock.pm
↑ Summary
blib/lib/Dist/Zilla/MintingProfile/Author/Plicease.pm »
| 1 | 2 | package Dist::Zilla::Plugin::Author::Plicease::Thanks 2.81 { | |||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use 5.022; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use experimental qw( postderef ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 2 | with 'Dist::Zilla::Role::MetaProvider'; | |||||||||
| 8 | 2 | with 'Dist::Zilla::Role::FileMunger'; | |||||||||
| 9 | 2 | with 'Dist::Zilla::Role::FileFinderUser' => { | |||||||||
| 10 | default_finders => [ ':InstallModules', ':ExecFiles' ], | ||||||||||
| 11 | }; | ||||||||||
| 12 | |||||||||||
| 13 | # ABSTRACT: munge the AUTHOR section | ||||||||||
| 14 | |||||||||||
| 15 | |||||||||||
| 16 | 2 | has original => ( | |||||||||
| 17 | is => 'ro', | ||||||||||
| 18 | isa => 'Str', | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | 2 | has current => ( | |||||||||
| 22 | is => 'ro', | ||||||||||
| 23 | isa => 'Str', | ||||||||||
| 24 | ); | ||||||||||
| 25 | |||||||||||
| 26 | has contributor => ( | ||||||||||
| 27 | is => 'ro', | ||||||||||
| 28 | isa => 'ArrayRef[Str]', | ||||||||||
| 29 | 2 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 2 | ); | |||||||||
| 31 | |||||||||||
| 32 | 4 | ▶ | sub mvp_multivalue_args { qw( contributor ) } | ||||||||
|
Subroutine
mvp_multivalue_args: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | sub munge_files | ||||||||||
| 35 | 4 | ▶ | { | ||||||||
|
Subroutine
munge_files: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 36 | 4 | my($self) = @_; | |||||||||
| 37 | 4 | $self->munge_file($_) for $self->found_files->@*; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | sub _escape ($) | ||||||||||
| 41 | 12 | ▶ | { | ||||||||
|
Subroutine
_escape: called CC=1 SCAR=0.0
| |||||||||||
| 42 | 12 | my($txt) = @_; | |||||||||
| 43 | 12 | my %map = qw( | |||||||||
| 44 | < lt | ||||||||||
| 45 | > gt | ||||||||||
| 46 | ); | ||||||||||
| 47 | 12 | $txt =~ s{([<>])}{E<$map{$1}>}g; | |||||||||
| 48 | 12 | $txt; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | sub munge_file | ||||||||||
| 52 | 4 | ▶ | { | ||||||||
|
Subroutine
munge_file: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 53 | 4 | my($self, $file) = @_; | |||||||||
| 54 | |||||||||||
| 55 | 4 | ▶ | $self->log_fatal('requires at least current') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | unless $self->current; | ||||||||||
| 57 | |||||||||||
| 58 | 4 | ▶ | my $replacer = sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 59 | 4 | my @list; | |||||||||
| 60 | 4 | push @list, '=head1 AUTHOR', ''; | |||||||||
| 61 | 4 | ▶ | if($self->original) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | { | ||||||||||
| 63 | 2 | push @list, 'Original author: ' . _escape $self->original, | |||||||||
| 64 | '', | ||||||||||
| 65 | 'Current maintainer: ' . _escape $self->current, | ||||||||||
| 66 | ''; | ||||||||||
| 67 | } | ||||||||||
| 68 | else | ||||||||||
| 69 | { | ||||||||||
| 70 | 2 | push @list, 'Author: ' . _escape $self->current, | |||||||||
| 71 | ''; | ||||||||||
| 72 | } | ||||||||||
| 73 | 4 | ▶ | if($self->contributor->@* > 0) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | { | ||||||||||
| 75 | 2 | push @list, 'Contributors:', '', map { (_escape $_, '') } $self->contributor->@*; | |||||||||
| 76 | } | ||||||||||
| 77 | 4 | return join "\n", @list, ''; | |||||||||
| 78 | 4 | }; | |||||||||
| 79 | |||||||||||
| 80 | 4 | my $content = $file->content; | |||||||||
| 81 | 4 | ▶ | unless($content =~ s{^=head1 AUTHOR.*(=head1 COPYRIGHT)}{$replacer->() . $1}sem) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | { | ||||||||||
| 83 | 0 | $self->log_fatal('could not replace AUTHOR section'); | |||||||||
| 84 | } | ||||||||||
| 85 | 4 | $file->content($content); | |||||||||
| 86 | |||||||||||
| 87 | 4 | return; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | sub metadata | ||||||||||
| 91 | 4 | ▶ | { | ||||||||
|
Subroutine
metadata: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 92 | 4 | my ($self) = @_; | |||||||||
| 93 | |||||||||||
| 94 | 4 | my @contributors = $self->contributor->@*; | |||||||||
| 95 | 4 | ▶ | unshift @contributors, $self->current if $self->current; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 4 | ▶ | unshift @contributors, $self->original if $self->original; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | |||||||||||
| 98 | 4 | return +{ x_contributors => \@contributors }; | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||
| 102 | |||||||||||
| 103 | } | ||||||||||
| 104 | |||||||||||
| 105 | 2 | 1; | |||||||||
| 106 | |||||||||||
| 107 | __END__ | ||||||||||