File Coverage

blib/lib/Dist/Inkt/Role/WriteCREDITS.pm
Criterion Covered Total %
statement 6 26 23.0
branch 0 8 0.0
condition 0 2 0.0
subroutine 2 3 66.6
pod 0 1 0.0
total 8 40 20.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.022';
5              
6 1     1   1103 use Moose::Role;
  1         394593  
  1         4  
7 1     1   5440 use namespace::autoclean;
  1         6383  
  1         4  
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 0     0 0   my $self = shift;
30 0           my $file = $self->targetfile('CREDITS');
31 0 0         $file->exists and return $self->log('Skipping %s; it already exists', $file);
32 0           $self->log('Writing %s', $file);
33 0 0 0       $self->rights_for_generated_files->{'CREDITS'} ||= [
34             'None', 'public-domain'
35             ] if $self->DOES('Dist::Inkt::Role::WriteCOPYRIGHT');
36            
37 0           my $fh = $file->openw_utf8;
38            
39 0           my %already;
40 0           for my $role (qw/ maintainer contributor thanks /)
41             {
42 0           (my $method = "gather_all_${role}s") =~ s/ss$/s/s;
43             my @peeps =
44 0           sort { $a->to_string cmp $b->to_string }
45 0 0         grep { blessed($_) and not $already{$_}++ }
  0            
46             $self->doap_project->$method;
47 0 0         next unless @peeps;
48            
49 0           printf {$fh} ("%s:\n", ucfirst $role);
  0            
50 0           printf {$fh} ("- %s\n", $_->to_string) for @peeps;
  0            
51 0           printf {$fh} ("\n");
  0            
52             }
53            
54 0           close($fh);
55             }
56              
57             1;