| 1 | package Dist::Zilla::Plugin::CoderwallEndorse; | ||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:YANICK'; | |||||||||||||||||||||||||||
| 3 | # ABSTRACT: Adds a Coderwall 'endorse' button to README Markdown file (DEPRECATED) | ||||||||||||||||||||||||||||
| 4 | 2 | $Dist::Zilla::Plugin::CoderwallEndorse::VERSION = '0.2.1'; | |||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use List::Util qw/ first /; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Dist::Zilla::Role::File::ChangeNotification; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 2 | with qw/ | |||||||||||||||||||||||||||
| 16 | Dist::Zilla::Role::Plugin | ||||||||||||||||||||||||||||
| 17 | Dist::Zilla::Role::FileMunger | ||||||||||||||||||||||||||||
| 18 | /; | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | has users => ( | |||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||
| 22 | isa => 'Str', | ||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | has "filename" => ( | |||||||||||||||||||||||||||
| 26 | isa => 'Str', | ||||||||||||||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||||||||||||
| 28 | default => 'README.mkdn', | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | has mapping => ( | ||||||||||||||||||||||||||||
| 32 | traits => [ 'Hash' ], | ||||||||||||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||||||||||
| 34 | isa => 'HashRef', | ||||||||||||||||||||||||||||
| 35 | lazy => 1, | ||||||||||||||||||||||||||||
| 36 | 1 | ▶ | default => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 37 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 38 | 1 | my %m; | |||||||||||||||||||||||||||
| 39 | 1 | for my $p ( split /\s*,\s*/, $self->users ) { | |||||||||||||||||||||||||||
| 40 | 2 | my( $cd, $auth) = $p =~ /(\w+)\s*:\s*(.+?)\s*$/; | |||||||||||||||||||||||||||
| 41 | 2 | $m{$auth} = $cd; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | return \%m; | |||||||||||||||||||||||||||
| 45 | }, | ||||||||||||||||||||||||||||
| 46 | 2 | handles => { | |||||||||||||||||||||||||||
| 47 | 'authors' => 'keys', | ||||||||||||||||||||||||||||
| 48 | 'cd_user' => 'get', | ||||||||||||||||||||||||||||
| 49 | }, | ||||||||||||||||||||||||||||
| 50 | ); | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 2 | has "_last_content" => ( | |||||||||||||||||||||||||||
| 53 | isa => 'Str', | ||||||||||||||||||||||||||||
| 54 | is => 'rw', | ||||||||||||||||||||||||||||
| 55 | default => '', | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | sub munge_files { | ||||||||||||||||||||||||||
|
Subroutine
munge_files: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 1 | my $self = shift; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 1 | my $filename = $self->filename; | |||||||||||||||||||||||||||
| 62 | 1 | ▶ | my( $file ) = grep { $_->name eq $filename } @{ $self->zilla->files } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | or return $self->log([ "file '%s' not found", $filename ]); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 1 | $self->munge_file($file); | |||||||||||||||||||||||||||
| 66 | 1 | $self->watch($file); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | ▶ | sub watch { | ||||||||||||||||||||||||||
|
Subroutine
watch: called CC=2 SCAR=10.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | 1 | my( $self, $file ) = @_; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 1 | ▶ | Dist::Zilla::Role::File::ChangeNotification->meta->apply($file) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | unless $file->does('Dist::Zilla::Role::File::ChangeNotification'); | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | my $plugin = $self; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | $file->on_changed(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 77 | 0 | my ($self, $newcontent) = @_; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | $self->_content_checksum(0); | |||||||||||||||||||||||||||
| 80 | 0 | $self->watch_file; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | # If the new content is actually different, recalculate | ||||||||||||||||||||||||||||
| 83 | # the content based on the updates. | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return if $newcontent eq $plugin->_last_content; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | $plugin->log_debug('someone tried to munge ' . $self->name . ' after we read from it. Making modifications again...'); | |||||||||||||||||||||||||||
| 87 | 0 | $plugin->munge_file($file); | |||||||||||||||||||||||||||
| 88 | 1 | }); | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 1 | $file->watch_file; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | sub munge_file { | ||||||||||||||||||||||||||
|
Subroutine
munge_file: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | 1 | my( $self, $file ) = @_; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 1 | $self->log_debug([ 'CoderwallEndorse updating contents of %s in dist', $file->name ]); | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | my $new_content; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | for my $line ( split /\n/, $file->content ) { | |||||||||||||||||||||||||||
| 101 | 7 | ▶ | if ( $line=~ /^# AUTHOR/ ... $line =~ /^#/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 5 | for my $auth ( $self->authors ) { | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # author not mentioned, or endorse link already there | ||||||||||||||||||||||||||||
| 105 | 10 | ▶ | next if -1 == index $line, $auth | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
index($line, $auth) == -1 or index($line, "[endorse]") != -1
MC/DC50%1/2
index($line, $auth) == -1 or index($line, "[endorse]") != -1
index($line, $auth) == -1
index($line, "[endorse]") != -1
Truth table66%2/3
A or B
A= index($line, $auth) == -1B= index($line, "[endorse]") != -1
| |||||||||||||||||||||||||||||
| 106 | or -1 != index $line, '[endorse]'; | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 2 | $line .= sprintf " [](http://coderwall.com/%s)", | |||||||||||||||||||||||||||
| 109 | ( $self->cd_user($auth) ) x 2; | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | 7 | $new_content .= $line."\n"; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 1 | $self->_last_content($new_content); | |||||||||||||||||||||||||||
| 117 | 1 | $file->content($new_content); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 2 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 121 | 2 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 2 | 1; | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | __END__ | ||||||||||||||||||||||||||||