File Coverage

blib/lib/Dist/Inkt/Role/WriteCREDITS.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Dist::Inkt::Role::WriteCREDITS;
2              
3             our $AUTHORITY = 'cpan:TOBYINK';
4             our $VERSION = '0.021';
5              
6 1     1   1320 use Moose::Role;
  0            
  0            
7             use namespace::autoclean;
8              
9             with 'Dist::Inkt::Role::RDFModel';
10              
11             after PopulateMetadata => sub {
12             my $self = shift;
13            
14             my @maint = $self->doap_project->gather_all_maintainers;
15             push @{ $self->metadata->{author} ||= [] }, map "$_", @maint if @maint;
16            
17             my %already = map +($_ => 1), @maint;
18             my @contrib = grep !$already{$_}, $self->doap_project->gather_all_contributors;
19             push @{ $self->metadata->{x_contributors} ||= [] }, map "$_", @contrib if @contrib;
20             };
21              
22             after BUILD => sub {
23             my $self = shift;
24             unshift @{ $self->targets }, 'CREDITS';
25             };
26              
27             sub Build_CREDITS
28             {
29             my $self = shift;
30             my $file = $self->targetfile('CREDITS');
31             $file->exists and return $self->log('Skipping %s; it already exists', $file);
32             $self->log('Writing %s', $file);
33             $self->rights_for_generated_files->{'CREDITS'} ||= [
34             'None', 'public-domain'
35             ] if $self->DOES('Dist::Inkt::Role::WriteCOPYRIGHT');
36            
37             my $fh = $file->openw_utf8;
38            
39             my %already;
40             for my $role (qw/ maintainer contributor thanks /)
41             {
42             (my $method = "gather_all_${role}s") =~ s/ss$/s/s;
43             my @peeps =
44             sort { $a->to_string cmp $b->to_string }
45             grep { blessed($_) and not $already{$_}++ }
46             $self->doap_project->$method;
47             next unless @peeps;
48            
49             printf {$fh} ("%s:\n", ucfirst $role);
50             printf {$fh} ("- %s\n", $_->to_string) for @peeps;
51             printf {$fh} ("\n");
52             }
53            
54             close($fh);
55             }
56              
57             1;