blib/lib/Dist/Zilla/Plugin/Test/NoBOM.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 73 CC 1 SCAR 6.9
CC
1
Cov
0%
mvp_multivalue_args
2.0
mvp_aliases
2.0
register_prereqs
2.0
CRAP 2.0
1 package Dist::Zilla::Plugin::Test::NoBOM;
2 $Dist::Zilla::Plugin::Test::NoBOM::VERSION = '0.003';
3  
4 # ABSTRACT: Author tests that ensure BOM is not used
5 # KEYWORDS: plugin test testing author development BOM
6  
7 use Moose;
8 use Path::Tiny;
9 use Sub::Exporter::ForMethods 'method_installer'; # method_installer returns a sub.
10 use Data::Section 0.004 # fixed header_re
11 { installer => method_installer }, '-setup';
12 use Moose::Util::TypeConstraints 'role_type';
13 use namespace::autoclean;
14  
15 with 'Dist::Zilla::Role::FileGatherer', 'Dist::Zilla::Role::FileMunger',
16 'Dist::Zilla::Role::TextTemplate',
17 'Dist::Zilla::Role::FileFinderUser' => {
18 method => 'found_files',
19 finder_arg_names => ['finder'],
20 default_finders => [ ':InstallModules', ':ExecFiles', ':TestFiles' ],
21 },
22 'Dist::Zilla::Role::PrereqSource';
23  
24 has filename => (
25 is => 'ro',
26 isa => 'Str',
27 lazy => 1,
28 default => sub { return 'xt/author/no-bom.t' },
29 );
30  
31 has files => (
32 isa => 'ArrayRef[Str]',
33 traits => ['Array'],
34 handles => { files => 'sort' },
35 lazy => 1,
36 default => sub { [] },
37 );
38  
39 has _file_obj => (
40 is => 'rw',
41 isa => role_type('Dist::Zilla::Role::File'),
42 );
43  
44 sub mvp_multivalue_args { qw(files) }
45 sub mvp_aliases { return { file => 'files' } }
46  
47 sub register_prereqs {
48 my $self = shift;
49 $self->zilla->register_prereqs(
50 {
51 phase => 'develop',
52 type => 'requires',
53 },
54 'Test::BOM' => 0,
55 'Test::More' => 0
56 );
57 }
58  
59 sub gather_files {
60 my $self = shift;
61  
62 require Dist::Zilla::File::InMemory;
63  
64 $self->add_file(
65 $self->_file_obj(
66 Dist::Zilla::File::InMemory->new(
67 name => $self->filename,
68 content => ${ $self->section_data('__TEST__') },
69 )
70 )
71 );
72 return;
73 }
74  
75 sub munge_files {
76 my $self = shift;
77  
78 my @filenames = map { path( $_->name )->relative('.')->stringify }
79 grep { not( $_->can('is_bytes') and $_->is_bytes ) } @{ $self->found_files };
80 push @filenames, $self->files;
81  
82 $self->log_debug( 'adding file ' . $_ ) foreach @filenames;
83  
84 my $file = $self->_file_obj;
85 $file->content(
86 $self->fill_in_string(
87 $file->content,
88 {
89 dist => \( $self->zilla ),
90 plugin => \$self,
91 filenames => \@filenames,
92 }
93 )
94 );
95  
96 return;
97 }
98  
99 __PACKAGE__->meta->make_immutable;
100  
101 =pod
102  
103 =encoding UTF-8
104  
105 =head1 NAME
106  
107 Dist::Zilla::Plugin::Test::NoBOM - Author tests that ensure BOM is not used
108  
109 =head1 VERSION
110  
111 version 0.003
112  
113 =head1 SYNOPSIS
114  
115 In your F<dist.ini>:
116  
117 [Test::NoBOM]
118 finder = my_finder
119 finder = other_finder
120  
121 =head1 DESCRIPTION
122  
123 This is a plugin that runs at the L<gather
124 files|Dist::Zilla::Role::FileGatherer> stage, providing the file
125 F<xt/author/no-bom.t>. This test program use L<Test::BOM> to
126 make sure that the files in your distribution don't start with a
127 byte-order-mark (BOM).
128  
129 =for Pod::Coverage::TrustPod mvp_aliases
130 register_prereqs
131 gather_files
132 munge_files
133  
134 =head1 CONFIGURATION OPTIONS
135  
136 This plugin accepts the following options:
137  
138 =head2 C<finder>
139  
140 =for stopwords FileFinder
141  
142 This is the name of a L<FileFinder|Dist::Zilla::Role::FileFinder> for finding
143 files to check. The default value is C<:InstallModules>,
144 C<:ExecFiles> (see also L<Dist::Zilla::Plugin::ExecDir>) and C<:TestFiles>;
145 this option can be used more than once.
146  
147 Other predefined finders are listed in
148 L<Dist::Zilla::Role::FileFinderUser/default_finders>.
149 You can define your own with the
150 L<[FileFinder::ByName]|Dist::Zilla::Plugin::FileFinder::ByName> plugin.
151  
152 =head2 C<file>
153  
154 a filename to also test, in addition to any files found
155 earlier. This option can be repeated to specify multiple additional files.
156  
157 =head2 C<filename>
158  
159 The filename of the test to add - defaults to F<xt/author/no-bom.t>.
160  
161 =head1 SEE ALSO
162  
163 =for :list * Test::BOM
164  
165 =head1 AUTHOR
166  
167 Gregor Goldbach <glauschwuffel@gmail.com>
168  
169 =head1 COPYRIGHT AND LICENSE
170  
171 This software is copyright (c) 2023 by Gregor Goldbach.
172  
173 This is free software; you can redistribute it and/or modify it under
174 the same terms as the Perl 5 programming language system itself.
175  
176 =cut
177  
178 __DATA__