File Coverage

blib/lib/Dist/Zilla/Plugin/ContributorCovenant.pm
Criterion Covered Total %
statement 21 26 80.7
branch 1 6 16.6
condition n/a
subroutine 8 8 100.0
pod 0 4 0.0
total 30 44 68.1


line stmt bran cond sub pod time code
1             package Dist::Zilla::Plugin::ContributorCovenant;
2             $Dist::Zilla::Plugin::ContributorCovenant::VERSION = '2.000000';
3             =head1 NAME
4              
5             Dist::Zilla::Plugin::ContributorCovenant - Add Contributor Covenant as Code of Conduct
6              
7             =head1 DESCRIPTION
8              
9             C<Dist::Zilla::Plugin::ContributorCovenant> adds the Contributor
10             Covenant to your CPAN build as C<CODE_OF_CONDUCT.md>. It pulls
11             email address of first author from C<dist.ini>. If none found,
12             it will type "GitHub / RT" instead.
13              
14             =head1 SYNOPSIS
15              
16             Add this one line to your dist.ini.
17              
18             [ContributorCovenant]
19              
20             If you want to leave a copy of Code Of Conduct in code repository,
21             You can add following lines to your dist.ini as well.
22              
23             [CopyFilesFromBuild]
24             copy = CODE_OF_CONDUCT.md
25              
26             Note that this plugin will prune other CODE_OF_CONDUCT.md files, to
27             avoid multiple CODE_OF_CONDUCT.md preventing the build.
28              
29             The version of this module will match the version of the Contributor
30             Covenant used. For instance, version 1.004001 will use Contributor
31             Covenant version 1.4.1.
32              
33             =cut
34              
35 1     1   3275233 use warnings;
  1         3  
  1         40  
36 1     1   6 use strict;
  1         3  
  1         22  
37              
38 1     1   5 use Moose;
  1         3  
  1         5  
39 1     1   7142 use Dist::Zilla::File::InMemory;
  1         90825  
  1         515  
40              
41             with qw/
42             Dist::Zilla::Role::Plugin
43             Dist::Zilla::Role::FileGatherer
44             Dist::Zilla::Role::FilePruner
45             Dist::Zilla::Role::TextTemplate
46             Dist::Zilla::Role::MetaProvider
47             /;
48              
49             sub metadata {
50 2     2 0 29320 return { 'x_contributor_covenant' => { 'version' => 0.02 } };
51             }
52              
53             has '+zilla' => (
54             handles => { authors => 'authors' },
55             );
56              
57             has contributor_covenant => (
58             is => 'ro',
59             lazy => 1,
60             default => sub {
61             my $self = shift;
62             my ($author, $email);
63              
64             $author = $self->authors->[0];
65             ($email) = $author =~ /<(.*)>/ if $author;
66             my $contact = $email || 'GitHub / RT';
67              
68             $self->fill_in_string(contributor_covenant_template(),{
69             contact => $contact,
70             });
71             },
72             );
73              
74             sub gather_files {
75 2     2 0 79780 my $self = shift;
76 2         88 $self->add_file(
77             Dist::Zilla::File::InMemory->new({
78             content => $self->contributor_covenant,
79             name => 'CODE_OF_CONDUCT.md',
80             })
81             );
82             }
83              
84             sub prune_files {
85 2     2 0 2281 my $self = shift;
86              
87 2         6 my @coc_files = grep {$_->name eq 'CODE_OF_CONDUCT.md'} @{$self->zilla->files};
  4         121  
  2         82  
88 2 50       99 return unless scalar @coc_files > 1;
89              
90             # We will keep COC file produced by this plugin
91 0         0 foreach my $file (@coc_files){
92 0         0 my $keep = 0;
93 0         0 foreach my $source ($file->added_by){
94 0 0       0 $keep = 1 if $source =~ 'Dist::Zilla::Plugin::ContributorCovenant';
95             }
96 0 0       0 $self->zilla->prune_file($file) unless $keep;
97             }
98              
99             }
100              
101             sub contributor_covenant_template {
102 2     2 0 18 return <<'END_TEMPLATE';
103             # Contributor Covenant Code of Conduct
104              
105             ## Our Pledge
106              
107             We as members, contributors, and leaders pledge to make participation in our
108             community a harassment-free experience for everyone, regardless of age, body
109             size, visible or invisible disability, ethnicity, sex characteristics, gender
110             identity and expression, level of experience, education, socio-economic status,
111             nationality, personal appearance, race, religion, or sexual identity
112             and orientation.
113              
114             We pledge to act and interact in ways that contribute to an open, welcoming,
115             diverse, inclusive, and healthy community.
116              
117             ## Our Standards
118              
119             Examples of behavior that contributes to a positive environment for our
120             community include:
121              
122             * Demonstrating empathy and kindness toward other people
123             * Being respectful of differing opinions, viewpoints, and experiences
124             * Giving and gracefully accepting constructive feedback
125             * Accepting responsibility and apologizing to those affected by our mistakes,
126             and learning from the experience
127             * Focusing on what is best not just for us as individuals, but for the
128             overall community
129              
130             Examples of unacceptable behavior include:
131              
132             * The use of sexualized language or imagery, and sexual attention or
133             advances of any kind
134             * Trolling, insulting or derogatory comments, and personal or political attacks
135             * Public or private harassment
136             * Publishing others' private information, such as a physical or email
137             address, without their explicit permission
138             * Other conduct which could reasonably be considered inappropriate in a
139             professional setting
140              
141             ## Enforcement Responsibilities
142              
143             Community leaders are responsible for clarifying and enforcing our standards of
144             acceptable behavior and will take appropriate and fair corrective action in
145             response to any behavior that they deem inappropriate, threatening, offensive,
146             or harmful.
147              
148             Community leaders have the right and responsibility to remove, edit, or reject
149             comments, commits, code, wiki edits, issues, and other contributions that are
150             not aligned to this Code of Conduct, and will communicate reasons for moderation
151             decisions when appropriate.
152              
153             ## Scope
154              
155             This Code of Conduct applies within all community spaces, and also applies when
156             an individual is officially representing the community in public spaces.
157             Examples of representing our community include using an official e-mail address,
158             posting via an official social media account, or acting as an appointed
159             representative at an online or offline event.
160              
161             ## Enforcement
162              
163             Instances of abusive, harassing, or otherwise unacceptable behavior may be
164             reported to the community leaders responsible for enforcement at
165             {{ $contact }}.
166             All complaints will be reviewed and investigated promptly and fairly.
167              
168             All community leaders are obligated to respect the privacy and security of the
169             reporter of any incident.
170              
171             ## Enforcement Guidelines
172              
173             Community leaders will follow these Community Impact Guidelines in determining
174             the consequences for any action they deem in violation of this Code of Conduct:
175              
176             ### 1. Correction
177              
178             **Community Impact**: Use of inappropriate language or other behavior deemed
179             unprofessional or unwelcome in the community.
180              
181             **Consequence**: A private, written warning from community leaders, providing
182             clarity around the nature of the violation and an explanation of why the
183             behavior was inappropriate. A public apology may be requested.
184              
185             ### 2. Warning
186              
187             **Community Impact**: A violation through a single incident or series
188             of actions.
189              
190             **Consequence**: A warning with consequences for continued behavior. No
191             interaction with the people involved, including unsolicited interaction with
192             those enforcing the Code of Conduct, for a specified period of time. This
193             includes avoiding interactions in community spaces as well as external channels
194             like social media. Violating these terms may lead to a temporary or
195             permanent ban.
196              
197             ### 3. Temporary Ban
198              
199             **Community Impact**: A serious violation of community standards, including
200             sustained inappropriate behavior.
201              
202             **Consequence**: A temporary ban from any sort of interaction or public
203             communication with the community for a specified period of time. No public or
204             private interaction with the people involved, including unsolicited interaction
205             with those enforcing the Code of Conduct, is allowed during this period.
206             Violating these terms may lead to a permanent ban.
207              
208             ### 4. Permanent Ban
209              
210             **Community Impact**: Demonstrating a pattern of violation of community
211             standards, including sustained inappropriate behavior, harassment of an
212             individual, or aggression toward or disparagement of classes of individuals.
213              
214             **Consequence**: A permanent ban from any sort of public interaction within
215             the community.
216              
217             ## Attribution
218              
219             This Code of Conduct is adapted from the [Contributor Covenant][homepage],
220             version 2.0, available at
221             https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
222              
223             Community Impact Guidelines were inspired by [Mozilla's code of conduct
224             enforcement ladder](https://github.com/mozilla/diversity).
225              
226             [homepage]: https://www.contributor-covenant.org
227              
228             For answers to common questions about this code of conduct, see the FAQ at
229             https://www.contributor-covenant.org/faq. Translations are available at
230             https://www.contributor-covenant.org/translations.
231             END_TEMPLATE
232             }
233              
234             __PACKAGE__->meta->make_immutable;
235              
236             1;
237              
238             __END__
239              
240             =head1 AUTHOR
241              
242             Kivanc Yazan C<< <kyzn at cpan.org> >>
243              
244             =head1 CONTRIBUTORS
245              
246             Joelle Maslak C<< <jmaslak at antelope.net> >>
247             D Ruth Holloway C<< <ruth at hiruthie.me> >>
248              
249             =head1 COPYRIGHT AND LICENSE
250              
251             This software is copyright (c) 2020 by Kivanc Yazan.
252              
253             This is free software; you can redistribute it and/or modify it under
254             the same terms as the Perl 5 programming language system itself.
255              
256             =head1 ATTRIBUTION
257              
258             - This module is based heavily on L<Dist::Zilla::Plugin::Covenant>.
259              
260             - Covenant text is taken from L<https://www.contributor-covenant.org/version/2/0/code_of_conduct/code_of_conduct.md>.
261              
262             =head1 SEE ALSO
263              
264             - Contributor Covenant, L<https://www.contributor-covenant.org/>
265              
266             - VM Brasseur's "The Importance of Ecosystem" Keynote, L<https://archive.org/details/yatpc2018-ecosystem>
267              
268             =cut