blib/lib/App/wordlist/blossom.pm

filter: Statementstmt 63.8% 30 / 47 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 90.0% 9 / 10 Podpod n/a totaltotal 59.0% 39 / 66 CC 5 SCAR 24.3
CC
5
Cov
55%
__ANON__
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 11.4
↑ Summary
1 ## no critic: InputOutput::ProhibitInteractiveTest
2 package App::wordlist::blossom;
3  
4 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use App::wordlist ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Perinci::Sub::Util qw(gen_modified_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
13 1 our $DATE = '2025-03-07'; # DATE
14 1 our $DIST = 'App-wordlist-blossom'; # DIST
15 1 our $VERSION = '0.002'; # VERSION
16  
17 1 our %SPEC;
18  
19 gen_modified_sub(
20 base_name => 'App::wordlist::wordlist',
21 output_name => 'wordlist_blossom',
22 add_args => {
23 pangram => {
24 summary => 'Only find pangrams',
25 schema => 'true*',
26 },
27 },
28 modify_args => {
29 1 ▶ wordlists => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
30 1 $_[0]{default} = ['EN::Enable'];
31 },
32 1 ▶ min_len => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 1 $_[0]{default} = 4;
34 },
35 },
36 remove_args => [
37 'action',
38 'lcpan',
39 'chars_unordered',
40 'chars_ordered',
41 ],
42 1 ▶ modify_meta => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
43 1 $_[0]{summary} = 'Help list words for Blossom word game';
44 1 delete $_[0]{'x.doc.faq'};
45 1 $_[0]{description} = <<'MARKDOWN';
46  
47 This is a wrapper to <prog:wordlist> designed to be a convenient helper to
48 supply words for Blossom word game. By default it greps from the `EN::Enable`
49 wordlist. It accepts a single string containing 7 letters, where the first
50 letter is the word in the middle (which must always be present in the words).
51 For example:
52  
53 AMGSOEN
54  
55 which is equivalent to this blossom:
56  
57 G S
58  
59  
60 M A O
61  
62  
63 N E
64  
65 This wrapper will form a regex pattern to search words satisfying the condition.
66 The additional arguments will be passed to <prog:wordlist>.
67  
68 MARKDOWN
69 $_[0]{examples} = [
70 {
71 1 argv => ['AMGSOEN'],
72 test => 0,
73 'x.doc.show_result' => 0,
74 },
75 {
76 argv => ['AMGSOEN', '--pangram'],
77 summary => 'Only find pangrams',
78 test => 0,
79 'x.doc.show_result' => 0,
80 },
81 {
82 argv => ['AMGSOEN', '--min-len', 10, '/(ness|one)/'],
83 summary => 'Only list words 10 letters or more, and matches some regex',
84 test => 0,
85 'x.doc.show_result' => 0,
86 },
87 ];
88 },
89 0 ▶ output_code => sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
90 0 my %args = @_;
91  
92 0 ▶ $args{arg} //= [];
Condition0%0/2
$args{"arg"} //= []
l!l
00
MC/DC0%0/1
$args{"arg"} //= []
$args{"arg"}
Truth table0%0/2
A
A= $args{"arg"}
Aresult
11
00
93  
94 0 ▶ return [400, "Please specify the 7 letters"] unless @{ $args{arg} } >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$args{"arg"};} >= 1 0 0 0
95 0 my $letters = lc(shift @{ $args{arg} });
96 0 ▶ return [400, "Invalid 7 letters, please specify exactly 7 letters"] unless $letters =~ /\A[a-z]{7}\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $letters =~ /\A[a-z]{7}\z/ 0 0 0
97  
98 0 my $re;
99 my @new_arg;
100 {
101 0 push @new_arg, "/".substr($letters,0,1)."/";
102 0 push @new_arg, "/\\A[$letters]{4,}\\z/";
103 0 ▶ push @new_arg, "/".join("", map { "(?=.*$_)" } (split //, $letters))."/" if $args{pangram};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"pangram"} 0 0 0
104 }
105  
106 0 $args{arg} = [@new_arg, @{ $args{arg} }];
107  
108 0 log_trace "Arguments passed to wordlist(): %s", \%args;
109 0 App::wordlist::wordlist(%args);
110 },
111 1 );
112  
113 1 1;
114 # ABSTRACT: A wordlist wrapper to help list words for Blossom word game
115  
116 __END__
↑ Summary