MetaCurator/Config.pm untested

filter: Statementstmt 0.0% 0 / 58 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 69 CC 1 SCAR 6.9
CC
1
Cov
0%
init_config
2.0
init_metapackager_config
2.0
BEGIN
2.0
CRAP 2.0
1 package CPAN::MetaCurator::Config;
2  
3 use boolean;
4 use feature 'say';
5  
6 use Config::Tiny;
7  
8 use Data::Dumper::Concise; # For Dumper().
9  
10 use File::Spec;
11  
12 use Mew;
13 use Mojo::Log;
14  
15 has config => (HashRef, default => sub {return {} }, chained => 1);
16  
17 has -config_path => (Str, default => 'data/cpan.metacurator.conf');
18  
19 has database_path => (Str, default => 'data/cpan.metacurator.sqlite');
20  
21 has -error => (Str, default => '', chained => 1);
22  
23 has home_path => (Str, default => '', chained => 1);
24  
25 # Available log levels are trace, debug, info, warn, error and fatal, in that order.
26  
27 has -log_level => (Str, default => 'info', chained => 1);
28  
29 has -logger => (Object, chained => 1);
30  
31 has metapackager_config => (HashRef, default => sub {return {} }, chained => 1);
32  
33 has -metapackager_config_path => (Str, default => 'data/cpan.metapackager.conf');
34  
35 has -metapackager_database_path => (Str, default => '/tmp/cpan.metapackager.sqlite');
36  
37 has -node_types => (ArrayRef, default => sub {return [qw/acronym known leaf see_also topic/]});
38  
39 # Warning. Order is important because of foreign key constraints.
40 # The tables are created in this order, and dropped in reverse order.
41 # Lastly, we process the topics table to extract the module names.
42 # See also Database.build_pad().
43  
44 has -table_names => (ArrayRef, default => sub{return [qw/constants log modules topics/]});
45  
46 has -tiddlers_path => (Str, default => 'data/tiddlers.json');
47  
48 has -visual_break => (Str, default => sub{return '-' x 50});
49  
50 our $VERSION = '1.34';
51  
52 # -----------------------------------------------
53  
54 sub init_config
55 {
56 my($self) = @_;
57 my($path) = File::Spec -> catfile($self -> home_path, $self -> config_path);
58 my($conf) = Config::Tiny -> read($path);
59 $conf = $conf -> {_};
60 $$conf{config_path} = $path;
61 $$conf{log_path} = File::Spec -> catfile($self -> home_path, $$conf{log_path});
62  
63 $self -> config($conf);
64 $self -> logger(Mojo::Log -> new(level => $self -> log_level, path => $$conf{log_path}) );
65  
66 } # End of init_config.
67  
68 # -----------------------------------------------
69  
70 sub init_metapackager_config
71 {
72 my($self) = @_;
73 my($path) = File::Spec -> catfile($self -> home_path, $self -> metapackager_config_path);
74 my($conf) = Config::Tiny -> read($path);
75 $conf = $conf -> {_};
76 $$conf{config_path} = $path;
77  
78 $self -> metapackager_config($conf);
79 $self -> logger -> debug("Leaving Config.init_metapackager_config()");
80  
81 } # End of init_metapackager_config.
82  
83 # --------------------------------------------------
84  
85 1;
86  
87 =head1 NAME
88  
89 CPAN::MetaCurator::Config - Manage the cpan.metacurator.sqlite database
90  
91 =head1 Synopsis
92  
93 See L<CPAN::MetaCurator/Synopsis>.
94  
95 =head1 Description
96  
97 L<CPAN::MetaCurator> implements an interface to the 'levies' database.
98  
99 =head1 Methods
100  
101 =head2 config()
102  
103 Returns a hashref of options read from the config file, which defaults to
104 C<config_name()> (data/cpan.metacurator.conf) under C<home_path()>.
105  
106 =head2 config_name()
107  
108 Returns a string holding the dir/name of the config file.
109  
110 =head1 Support
111  
112 Email the author.
113  
114 =head1 Author
115  
116 C<CPAN::MetaCurator> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2025.
117  
118 L<Home page|https://savage.net.au/index.html>.
119  
120 =head1 Copyright
121  
122 Australian copyright (c) 2025, Ron Savage.
123 All Programs of mine are 'OSI Certified Open Source Software';
124 you can redistribute them and/or modify them under the terms of
125 The Artistic License V 2, a copy of which is available at:
126 http://www.opensource.org/licenses/index.html
127  
128 =cut