MetaCurator/Search.pm untested

filter: Statementstmt 0.0% 0 / 105 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 135 CC 8 SCAR 23.9
CC
8
Cov
0%
check
30.0
fix_camel_case
12.0
report
6.0
CRAP 10.9
1 package CPAN::MetaCurator::Search;
2  
3 use boolean;
4 use feature 'say';
5 use open qw(:std :utf8);
6 use parent 'CPAN::MetaCurator::HTML';
7 use warnings qw(FATAL utf8); # Fatalize encoding glitches.
8  
9 use Data::Dumper::Concise; # For Dumper().
10  
11 use File::Slurper 'read_lines';
12 use File::Spec;
13  
14 use Mew;
15 use Mojo::JSON qw/to_json/;
16  
17 has names_path => (Str, default => sub{return 'data/module.names.txt'}, chained => 1);
18  
19 has report_type => (Str, default => sub{return 'topics'}, chained => 1);
20  
21 our $VERSION = '1.34';
22  
23 # --------------------------------------------------
24  
25 sub check
26 {
27 my($self) = @_;
28  
29 $self -> init_config;
30 $self -> init_db;
31  
32 my($pad) = $self -> build_pad;
33 my($database_path) = File::Spec -> catfile($self -> home_path, $self -> database_path);
34 my($names_path) = $self -> names_path;
35  
36 $self -> logger -> info("Searching modules table");
37 $self -> logger -> info("Reading: $database_path");
38 $self -> logger -> info("Reading: $names_path");
39  
40 my(@names) = read_lines($names_path);
41  
42 my($found, @found);
43 my(@not_found);
44 my(%seen);
45  
46 for my $name (@names)
47 {
48 $name = ($name =~ /^o (.+):/) ? $1 : '';
49  
50 next if (! $name);
51 next if ($seen{$name});
52  
53 $seen{$name} = true;
54 $found = exists $$pad{module_names}{$name};
55  
56 if ($found)
57 {
58 push @found, $name;
59 }
60 else
61 {
62 push @not_found, $name;
63 }
64 }
65  
66 $self -> logger -> info('Found:');
67 $self -> logger -> info(Dumper sort @found);
68 $self -> logger -> info('Not found:');
69 $self -> logger -> info(Dumper sort @not_found);
70 $self -> logger -> info('check() finished');
71  
72 return 1; # Success.
73  
74 } # End of check.
75  
76 # --------------------------------------------------
77 # Warning: This does not find all CamelCase usages.
78  
79 sub fix_camel_case
80 {
81 my($self) = @_;
82 my($data) = $self -> read_tiddlers_file;
83 my($pad) = $self -> pad;
84 my($regexp) = $self -> get_special_para_names_regexp($pad);
85 my($topics) = $self -> read_table('topics');
86 my($count) = 0;
87  
88 my($item);
89 my(@output);
90 my($text, $title, $topic);
91  
92 $self -> logger -> info("Size of data: $#$data");
93  
94 for my $index (0 .. $#$data)
95 {
96 $item = $$data[$index];
97 $text = $$item{text};
98 $title = $$item{title};
99  
100 next if ($title =~ $regexp);
101  
102 $count++;
103  
104 # Scan the $text looking for each topic not surrounded by [[]].
105  
106 for $topic (@$topics)
107 {
108 if ($text =~ /(.+?)(\s$$topic{title})(\s?.*)/gsm)
109 {
110 $text = "$1\[\[$2]]$3";
111 }
112 }
113  
114 $$item{text} = $text;
115  
116 push @output, $item;
117 }
118  
119 open(OUT, '>', 'data/new.tiddlers.json');
120 print OUT to_json([@output]);
121 close OUT;
122  
123 $self -> logger -> info("Input count: $count. Size of output: $#output");
124  
125 return 1;
126  
127 } # End of fix_camel_case.
128  
129 # --------------------------------------------------
130  
131 sub report
132 {
133 my($self) = @_;
134 my($data) = $self -> read_tiddlers_file;
135 my($pad) = $self -> pad;
136 my($regexp) = $self -> get_special_para_names_regexp($pad);
137  
138 my($text, $title);
139  
140 for my $index (0 .. $#$data)
141 {
142 $text = $$data[$index]{text};
143 $title = $$data[$index]{title};
144  
145 if ($title =~ $regexp)
146 {
147 $self -> logger -> warn("Skipping paragraph: $1");
148  
149 next;
150 }
151  
152 $self -> logger -> info("title: $title. text: $text");
153 $self -> logger -> info('-' x 50);
154 }
155  
156 return 1;
157  
158 } # End of report.
159  
160 # --------------------------------------------------
161  
162 1;
163  
164 =pod
165  
166 =head1 NAME
167  
168 CPAN::MetaCurator::Search - Parse output from scripts/parse.metacpan.recent.pl
169  
170 =head1 Machine-Readable Change Log
171  
172 The file Changes was converted into Changelog.ini by L<Module::Metadata::Changes>.
173  
174 =head1 Version Numbers
175  
176 Version numbers < 1.00 represent development versions. From 1.00 up, they are production versions.
177  
178 =head1 Support
179  
180 Email the author.
181  
182 =head1 Method check()
183  
184 Note: Module names are case-sensitive.
185  
186 The purpose is to read a file of module names and classify them as found (already in the db)
187 and not found (new). This makes updating Perl.Wiki.html much easier since I can ignore the former.
188  
189 This module is used via check.module.names.pl.
190  
191 =head1 Author
192  
193 L<CPAN::MetaCurator> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2025.
194  
195 My homepage: L<https://savage.net.au/>.
196  
197 =head1 Copyright
198  
199 Australian copyright (c) 2026, Ron Savage.
200  
201 All Programs of mine are 'OSI Certified Open Source Software';
202 you can redistribute them and/or modify them under the terms of
203 The Perl License, a copy of which is available at:
204 http://dev.perl.org/licenses/
205  
206 =cut