File Coverage

blib/lib/Dist/Zilla/Stash/Contributors.pm
Criterion Covered Total %
statement 8 10 80.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 12 14 85.7


line stmt bran cond sub pod time code
1             package Dist::Zilla::Stash::Contributors;
2             BEGIN {
3 1     1   639 $Dist::Zilla::Stash::Contributors::AUTHORITY = 'cpan:YANICK';
4             }
5             {
6             $Dist::Zilla::Stash::Contributors::VERSION = '0.1.0';
7             }
8             # ABSTRACT: Stash containing list of contributors
9              
10 1     1   5 use strict;
  1         2  
  1         22  
11 1     1   3 use warnings;
  1         2  
  1         16  
12              
13 1     1   1586 use Moose;
  0            
  0            
14              
15             use Dist::Zilla::Stash::Contributors::Contributor;
16              
17             has contributors => (
18             traits => [ 'Hash' ],
19             isa => 'HashRef[Dist::Zilla::Stash::Contributors::Contributor]',
20             is => 'ro',
21             default => sub { {} },
22             handles => {
23             _all_contributors => 'values',
24             nbr_contributors => 'count',
25             },
26             );
27              
28              
29             sub all_contributors {
30             my $self = shift;
31              
32             return sort { $a->stringify cmp $b->stringify } $self->_all_contributors;
33             }
34              
35              
36             sub add_contributors {
37             my ( $self, @contributors ) = @_;
38              
39             for my $c ( @contributors ) {
40             my $name = $c;
41             my $email;
42             $email = $1 if $name =~ s/\s*<(.*?)>\s*//;
43              
44             my $object = Dist::Zilla::Stash::Contributors::Contributor->new(
45             name => $name, email => $email
46             );
47              
48             $self->contributors->{ $object->stringify } ||= $object;
49             }
50              
51             }
52              
53             __PACKAGE__->meta->make_immutable;
54              
55             1;
56              
57             __END__
58              
59             =pod
60              
61             =head1 NAME
62              
63             Dist::Zilla::Stash::Contributors - Stash containing list of contributors
64              
65             =head1 VERSION
66              
67             version 0.1.0
68              
69             =head1 SYNOPSIS
70              
71             my $contrib_stash = $self->zilla->stash_named('%Contributors');
72              
73             unless ( $contrib_stash ) {
74             $contrib_stash = Dist::Zilla::Stash::Contributors->new;
75             $self->_register_stash('%Contributors', $contrib_stash );
76             }
77              
78             $contrib_stash->add_contributors( 'Yanick Champoux <yanick@cpan.org>' );
79              
80             =head1 DESCRIPTION
81              
82             If you are a L<Dist::Zilla> user, avert your eyes and read no more: this
83             module is not for general consumption but for authors of plugins dealing
84             with contributors harvesting or processing.
85              
86             Oh, you're one of those? Excellent. Well, here's the deal: this is a
87             stash that is meant to carry the contributors' information between plugins.
88             Plugins that gather contributors can populate the list with code looking like
89             this:
90              
91             sub before_build {
92             my $self = shift;
93              
94             ...; # gather @collaborators, somehow
95              
96             my $contrib_stash = $self->zilla->stash_named('%Contributors');
97             unless ( $contrib_stash ) {
98             $contrib_stash = Dist::Zilla::Stash::Contributors->new;
99             $self->_register_stash('%Contributors', $contrib_stash );
100             }
101              
102             $contrib_stash->add_contributors( @contributors );
103             }
104              
105             and plugin that use them:
106              
107             # of course, make sure this is run *after* the gatherers did their job
108             sub before_build {
109             my $self = shift;
110              
111             my $contrib_stash = $self->zilla->stash_named('%Contributors')
112             or return;
113              
114             my @contributors = $contrib_stash->all_contributors;
115             }
116              
117             And that's pretty much all you need to know beside that, internally, each contributor is represented by
118             a L<Dist::Zilla::Stash::Contributors::Contributor> object.
119              
120             =head1 METHODS
121              
122             =head2 all_contributors()
123              
124             Returns all contributors as C<Dist::Zilla::Stash::Contributors::Contributor>
125             objects. The collaborators are sorted alphabetically.
126              
127             =head2 nbr_contributors()
128              
129             Returns the number of contributors.
130              
131             =head2 add_contributors( @contributors )
132              
133             Adds the C<@contributors> to the stash. Duplicates are filtered out.
134              
135             Contributors can be L<Dist::Zilla::Stash::Contributors::Contributor> objects
136             or strings of the format 'Full Name <email@address.org>'.
137              
138             =head1 AUTHOR
139              
140             Yanick Champoux <yanick@cpan.org>
141              
142             =head1 COPYRIGHT AND LICENSE
143              
144             This software is copyright (c) 2013 by Yanick Champoux.
145              
146             This is free software; you can redistribute it and/or modify it under
147             the same terms as the Perl 5 programming language system itself.
148              
149             =cut