Pod/Wordlist/Author/TABULO.pm

filter: Statementstmt 86.6% 52 / 60 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 3 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 14 / 16 Podpod 40.0% 2 / 5 totaltotal 77.4% 72 / 93 CC 6 SCAR 9.0
CC
6
Cov
82%
learn_stopwords_from
6.3
delta
2.0
entire
2.0
CRAP 2.5
« Zest/Author/TABULO/Util/Text.pm ↑ Summary Zest/Author/TABULO/Util.pm »
1 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 package Pod::Wordlist::Author::TABULO;
7  
8 2 our $VERSION = '1.000014';
9 2 our $DEBUG = 0;
10  
11 2 ▶use Lingua::EN::Inflect 'PL';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Path::Tiny qw( path );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Zest::Author::TABULO::Util::ShareDir qw(dist_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Zest::Author::TABULO::Util::Text qw(lines_utf8_from strip_comments);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use parent qw(Pod::Wordlist);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Class::Tiny {
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 wordlist => \&_build_wordlist, # override
19 2 };
20  
21 ##=== MODULE INIT
22  
23 #== DELTA: is a default instance -- which ONLY contains words defined here (see INIT code below)
24 ### XXX: wordlist (even if empty) MUST be provided (otherwise => infinite loop!)
25 2 my $DELTA = __PACKAGE__->new(
26 wordlist => +{},
27 );
28  
29 2 ▶my @teachers = map { dist_file("$_", 'stopwords') // () } ( __PACKAGE__, 'Dist::Zilla::PluginBundle::Author::TABULO' );
Condition33%1/3
dist_file("$_", "stopwords") // ()
l!l&&r!l&&!r
400
MC/DC0%0/2
dist_file("$_", "stopwords") // ()
dist_file("$_", "stopwords") ()
Truth table33%1/3
A // B
A= dist_file("$_", "stopwords")B= ()
ABresult
1X1
011
000
30 2 $DELTA->learn_stopwords_from($_) for @teachers, "" . <DATA>;
31  
32 #== ENTIRE: is another default instance -- which ALSO contains words from our SUPER (normally, <Pod::Wordlist>)
33 ### XXX: wordlist (even if empty) MUST be provided (otherwise => infinite loop!)
34 my $ENTIRE = __PACKAGE__->new(
35 2 wordlist => +{ %{ ; __PACKAGE__->SUPER::new()->wordlist }, %{; $DELTA->wordlist } },
36 );
37  
38 ##=== Methods (class)
39 0 ▶sub delta { __PACKAGE__->new( wordlist=> +{ %{ $DELTA->wordlist} }) }
Subroutine delta: not called CC=1 SCAR=6.9
Pod undocumented
40 4 ▶sub default { __PACKAGE__->new( wordlist=> +{ %{ $DELTA->wordlist} }) }
Subroutine default: called CC=1 SCAR=0.0
Pod undocumented
41 0 ▶sub entire { __PACKAGE__->new( wordlist=> +{ %{ $ENTIRE->wordlist} }) }
Subroutine entire: not called CC=1 SCAR=6.9
Pod undocumented
42  
43 ##=== Instance methods
44 4 ▶sub _build_wordlist {
Subroutine _build_wordlist: called CC=1 SCAR=0.0
45 4 return +{ %{ $_[0]->default->wordlist } }; # a copy of DEFAULT wordlist.
46 }
47  
48 #pod =method learn_stopwords_from (OVERRIDDEN from parent)
49 #pod
50 #pod Like the inherited C<learn_stopwords> method, but this one accepts any number of arguments which will be I<learned> in a loop.
51 #pod
52 #pod So, it basically saves you loop.
53 #pod
54 #pod =cut
55 300 ▶sub learn_stopwords {
Subroutine learn_stopwords: called CC=2 SCAR=6.9
Pod documented
56 300 my $self = shift;
57 300 $self->SUPER::learn_stopwords($_) for @_;
58 }
59  
60 #pod =method learn_stopwords_from
61 #pod
62 #pod Like the inherited C<learn_stopwords> method, but this one also accepts, in addition to simple scalars, any number of things that appear to be capable of providing textual content, such as:
63 #pod
64 #pod * simple scalar
65 #pod * IO::Handle (which will be read from)
66 #pod * Any object that I<can> do C<lines_utf8()>, such as and instance of L<Path::Tiny>
67 #pod
68 #pod =cut
69 8 ▶sub learn_stopwords_from {
Subroutine learn_stopwords_from: called CC=5 SCAR=18.4
Pod documented
70 8 my $self = shift;
71 8 for my $arg (@_) {
72 10 ▶ if ( ref($arg) and my $wordlist = eval { $arg->can('wordlist') } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $arg and my $wordlist = eval { do { $arg->can('wordlist') } }) { } 0 10 10
Condition66%2/3
ref $arg and my $wordlist = eval { do { $arg->can("wordlist") } }
!ll&&!rl&&r
640
MC/DC0%0/2
ref $arg and my $wordlist = eval { do { $arg->can("wordlist") } }
ref $arg my $wordlist = eval { do { $arg->can("wordlist") } }
Truth table66%2/3
A and B
A= ref $argB= my $wordlist = eval { do { $arg->can("wordlist") } }
ABresult
0X0
100
111
73 0 %{ $self->wordlist } = ( %{ $self->wordlist }, %{ $arg->$wordlist() } ); # learn from another Wordlist
74 } else {
75 10 my @content = map { ( strip_comments( lines_utf8_from($_) ) ) } ($arg);
76 10 $self->learn_stopwords($_) for @content; # learn from another source ($scalar, IO::Handle, file (Path::Tiny))
77 }
78 }
79 }
80  
81 2 1;
82  
83 # ABSTRACT: Add words for spell checking POD à la TABULO
84 # CREDITS: Shamelessly adopted from <Pod::Wordlist::hanekomu>
85  
86 ## TODO: Actually document some of the below
87 #pod =for Pod::Coverage default delta entire
88 #pod
89 #pod =pod
90 #pod
91 #pod =head1 SYNOPSIS
92 #pod
93 #pod # in some Dist::Zilla::PluginBundle::Foo
94 #pod
95 #pod sub configure {
96 #pod
97 #pod my $stopwords = Pod::Wordlist::Author::TABULO->new;
98 #pod $self->add_plugin(
99 #pod [ 'Test::PodSpelling' => { stopwords => [ sort keys %{ $stopwords->wordlist } ] } ],
100 #pod );
101 #pod }
102 #pod
103 #pod
104 #pod
105 #pod =head1 DESCRIPTION
106 #pod
107 #pod This is an EXPERIMENTAL module for my personal use within my authoring workflows (especially with L<Dist::Zilla>).
108 #pod
109 #pod It's there because I don't want to lose my time adding the same stopwords in multiple places.
110 #pod
111 #pod You shouldn't use this module. Everything in and about it is subject to change without prior notice or deprecation cycles.
112 #pod
113 #pod Even if it doesn't manage to eat your cat, it can surely put bad words in your mouth :-)
114 #pod
115 #pod Currently, the extra stopwords injected include: some monikers, aliases (e.g. TABULON), CPAN IDs, technical terms,
116 #pod and other words commonly used (by me) that are not included in the default word list.
117 #pod
118 #pod =head1 HOW IT WORKS
119 #pod
120 #pod This module sub-classes L<Pod::Wordlist> and overrides its C<wordlist> method, injecting a bunch words to the returned wordlist.
121 #pod
122 #pod Unlike L<Pod::Wordlist::hanekomu> (DEPRECATED), this module does NOT do anything behind the scenes:
123 #pod
124 #pod Namely, it doesn't directly interact with L<Test::Spelling>. Therefore, merely loading this module will NOT automagically add its stopwords for spell-checking.
125 #pod
126 #pod Instead, it just sits there and provides the same API as L<Pod::Wordlist>, augmenting the stopwords provided by that module.
127 #pod
128 #pod So, in order to benefit from it, one needs to somehow tell L<Test::Spelling> to actually make use of it (which is construed as a feature).
129 #pod
130 #pod First, I thought that could easily be achieved since the L<Dist::Zilla> plugin L<[Test::PodSpelling]|Dist::Zilla::Plugin::Test::PodSpelling> advertises just such a configuration parameter (C<wordlist>) that could have been given within C<dist.ini> or thru a PluginBundle, which is how I intended to use it.
131 #pod
132 #pod Apparently not... From what I gather, even though L<Dist::Zilla::Plugin::Test::PodSpelling> does indeed pass the buck ( C<wordlist>) along, the underlying modules (L<Test::PodSpelling> and L<Pod::Spelling>) merely ignore that setting... Perhaps a bug report or a PR is due for at least one of those.authoring.
133 #pod
134 #pod Anyhow, in the end, I had to grab the stopwords provided by this module and shove those into the C<stopwords> parameter of the L<Dist::Zilla> plugin L<[Test::PodSpelling]|Dist::Zilla::Plugin::Test::PodSpelling>. That seems to work like a charm.
135 #pod
136 #pod For the moment, this had to be done in my personal L<PluginBundle|Dist::Zilla::PluginBundle::Author::TABULO> since you can't execute code in C<dist.ini>. It's kind of a shame, but it works!
137 #pod
138 #pod =head1 DEFAULT STOPWORD SOURCES (a.k.a. default @teachers)
139 #pod
140 #pod By default, this module will acquire its wordlist from any or all of the below sources:
141 #pod
142 #pod * $DIST_SHARE_DIR/stopwords (of this distro)
143 #pod
144 #pod * <DATA> section (of this module)
145 #pod
146 #pod Those sources result in what I call the "I<DELTA>" dictionary (as opposed to the I<ENTIRE> dictionary that would include the wordlist from L<Pod::Wordlist> as well).authoring.ext/Dist-Milla/lib/Dist/Milla.pm
147 #pod
148 #pod Since I<DELTA> is the default, you can get the I<DELTA> dictionary like below :
149 #pod
150 #pod my $lexicon = Pod::Wordlist::Author::TABULO->new();
151 #pod $stopwords = $lexicon->wordlist() # This will get you the I<delta>.
152 #pod
153 #pod If you want the I<ENTIRE> wordlist (including also wordlist from L<Pod::Wordlist>), you would have to do:
154 #pod
155 #pod C<stopwords> is expected to be a plain text file with whitespace separated words in it.
156 #pod
157 #pod # Line comments are honored
158 #pod
159 #pod So are side comments # like this
160 #pod
161 #pod =head1 CREDITS
162 #pod
163 #pod Adopted the initial code from L<Pod::Wordlist::hanekomu> (DEPRECATED), but the mechanism of hooking into the spell-checking is entirely different.
164 #pod
165 #pod =head1 SEE ALSO
166 #pod
167 #pod * L<Pod::Wordlist>
168 #pod * L<Test::Spelling>
169 #pod * L<Dist::Zilla::Plugin::Test::PodSpelling>
170 #pod
171 #pod
172 #pod =cut
173  
174 =pod
175  
176 =encoding UTF-8
177  
178 =for :stopwords Tabulo[n]
179  
180 =head1 NAME
181  
182 Pod::Wordlist::Author::TABULO - Add words for spell checking POD à la TABULO
183  
184 =head1 VERSION
185  
186 version 1.000014
187  
188 =head1 SYNOPSIS
189  
190 # in some Dist::Zilla::PluginBundle::Foo
191  
192 sub configure {
193  
194 my $stopwords = Pod::Wordlist::Author::TABULO->new;
195 $self->add_plugin(
196 [ 'Test::PodSpelling' => { stopwords => [ sort keys %{ $stopwords->wordlist } ] } ],
197 );
198 }
199  
200 =head1 DESCRIPTION
201  
202 This is an EXPERIMENTAL module for my personal use within my authoring workflows (especially with L<Dist::Zilla>).
203  
204 It's there because I don't want to lose my time adding the same stopwords in multiple places.
205  
206 You shouldn't use this module. Everything in and about it is subject to change without prior notice or deprecation cycles.
207  
208 Even if it doesn't manage to eat your cat, it can surely put bad words in your mouth :-)
209  
210 Currently, the extra stopwords injected include: some monikers, aliases (e.g. TABULON), CPAN IDs, technical terms,
211 and other words commonly used (by me) that are not included in the default word list.
212  
213 =head1 METHODS
214  
215 =head2 learn_stopwords_from (OVERRIDDEN from parent)
216  
217 Like the inherited C<learn_stopwords> method, but this one accepts any number of arguments which will be I<learned> in a loop.
218  
219 So, it basically saves you loop.
220  
221 =head2 learn_stopwords_from
222  
223 Like the inherited C<learn_stopwords> method, but this one also accepts, in addition to simple scalars, any number of things that appear to be capable of providing textual content, such as:
224  
225 * simple scalar
226 * IO::Handle (which will be read from)
227 * Any object that I<can> do C<lines_utf8()>, such as and instance of L<Path::Tiny>
228  
229 =for Pod::Coverage default delta entire
230  
231 =head1 HOW IT WORKS
232  
233 This module sub-classes L<Pod::Wordlist> and overrides its C<wordlist> method, injecting a bunch words to the returned wordlist.
234  
235 Unlike L<Pod::Wordlist::hanekomu> (DEPRECATED), this module does NOT do anything behind the scenes:
236  
237 Namely, it doesn't directly interact with L<Test::Spelling>. Therefore, merely loading this module will NOT automagically add its stopwords for spell-checking.
238  
239 Instead, it just sits there and provides the same API as L<Pod::Wordlist>, augmenting the stopwords provided by that module.
240  
241 So, in order to benefit from it, one needs to somehow tell L<Test::Spelling> to actually make use of it (which is construed as a feature).
242  
243 First, I thought that could easily be achieved since the L<Dist::Zilla> plugin L<[Test::PodSpelling]|Dist::Zilla::Plugin::Test::PodSpelling> advertises just such a configuration parameter (C<wordlist>) that could have been given within C<dist.ini> or thru a PluginBundle, which is how I intended to use it.
244  
245 Apparently not... From what I gather, even though L<Dist::Zilla::Plugin::Test::PodSpelling> does indeed pass the buck ( C<wordlist>) along, the underlying modules (L<Test::PodSpelling> and L<Pod::Spelling>) merely ignore that setting... Perhaps a bug report or a PR is due for at least one of those.authoring.
246  
247 Anyhow, in the end, I had to grab the stopwords provided by this module and shove those into the C<stopwords> parameter of the L<Dist::Zilla> plugin L<[Test::PodSpelling]|Dist::Zilla::Plugin::Test::PodSpelling>. That seems to work like a charm.
248  
249 For the moment, this had to be done in my personal L<PluginBundle|Dist::Zilla::PluginBundle::Author::TABULO> since you can't execute code in C<dist.ini>. It's kind of a shame, but it works!
250  
251 =head1 DEFAULT STOPWORD SOURCES (a.k.a. default @teachers)
252  
253 By default, this module will acquire its wordlist from any or all of the below sources:
254  
255 * $DIST_SHARE_DIR/stopwords (of this distro)
256  
257 * <DATA> section (of this module)
258  
259 Those sources result in what I call the "I<DELTA>" dictionary (as opposed to the I<ENTIRE> dictionary that would include the wordlist from L<Pod::Wordlist> as well).authoring.ext/Dist-Milla/lib/Dist/Milla.pm
260  
261 Since I<DELTA> is the default, you can get the I<DELTA> dictionary like below :
262  
263 my $lexicon = Pod::Wordlist::Author::TABULO->new();
264 $stopwords = $lexicon->wordlist() # This will get you the I<delta>.
265  
266 If you want the I<ENTIRE> wordlist (including also wordlist from L<Pod::Wordlist>), you would have to do:
267  
268 C<stopwords> is expected to be a plain text file with whitespace separated words in it.
269  
270 # Line comments are honored
271  
272 So are side comments # like this
273  
274 =head1 CREDITS
275  
276 Adopted the initial code from L<Pod::Wordlist::hanekomu> (DEPRECATED), but the mechanism of hooking into the spell-checking is entirely different.
277  
278 =head1 SEE ALSO
279  
280 * L<Pod::Wordlist>
281 * L<Test::Spelling>
282 * L<Dist::Zilla::Plugin::Test::PodSpelling>
283  
284 =head1 AUTHORS
285  
286 Tabulo[n] <dev@tabulo.net>
287  
288 =head1 LEGAL
289  
290 This software is copyright (c) 2023 by Tabulo[n].
291  
292 This is free software; you can redistribute it and/or modify it under
293 the same terms as the Perl 5 programming language system itself.
294  
295 =cut
296  
297 __DATA__
« Zest/Author/TABULO/Util/Text.pm ↑ Summary Zest/Author/TABULO/Util.pm »