LocaleCountry/Config.pm

filter: Statementstmt 46.9% 23 / 49 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 3 / 3 totaltotal 47.7% 32 / 67 CC 4 SCAR 20.1
CC
4
Cov
42%
read
20.0
init
2.0
new
2.0
CRAP 7.5
↑ Summary LocaleCountry.pm »
1 package Benchmark::Featureset::LocaleCountry::Config;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Config::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use File::HomeDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use Hash::FieldHash ':all';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 fieldhash my %config => 'config';
15 1 fieldhash my %config_file_path => 'config_file_path';
16 1 fieldhash my %section => 'section';
17  
18 1 our $VERSION = '1.03';
19  
20 # -----------------------------------------------
21  
22 sub init
23 0 ▶{
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
24 0 my($self, $arg) = @_;
25  
26 0 return from_hash($self, $arg);
27  
28 } # End of init.
29  
30 # -----------------------------------------------
31  
32 sub new
33 0 ▶{
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
34 0 my($class, %arg) = @_;
35 0 my($self) = bless {}, $class;
36  
37 0 $self -> init(\%arg);
38  
39 0 my($path) = Path::Class::file(File::HomeDir -> my_dist_config('Benchmark-Featureset-LocaleCountry'), '.htbenchmark.featureset.localecountry.conf');
40  
41 0 $self -> read($path);
42  
43 0 return $self;
44  
45 } # End of new.
46  
47 # -----------------------------------------------
48  
49 sub read
50 0 ▶{
Subroutine read: not called CC=4 SCAR=30.0
Pod documented
51 0 my($self, $path) = @_;
52  
53 0 $self -> config_file_path($path);
54  
55 # Check [global].
56  
57 0 $self -> config(Config::Tiny -> read($path) );
58  
59 0 ▶ if (Config::Tiny -> errstr)
Branch: 1 branch
BranchTrueFalseTotal
if ("Config::Tiny"->errstr) 0 0 0
60 {
61 0 die Config::Tiny -> errstr;
62 }
63  
64 0 $self -> section('global');
65  
66 0 ▶ if (! ${$self -> config}{$self -> section})
Branch: 1 branch
BranchTrueFalseTotal
unless (${$self->config;}{$self->section}) 0 0 0
67 {
68 0 die "Config file '$path' does not contain the section [@{[$self -> section]}]\n";
69 }
70  
71 # Check [x] where x is host=x within [global].
72  
73 0 $self -> section(${$self -> config}{$self -> section}{'host'});
74  
75 0 ▶ if (! ${$self -> config}{$self -> section})
Branch: 1 branch
BranchTrueFalseTotal
unless (${$self->config;}{$self->section}) 0 0 0
76 {
77 0 die "Config file '$path' does not contain the section [@{[$self -> section]}]\n";
78 }
79  
80 # Move desired section into config, so caller can just use $self -> config to get a hashref.
81  
82 0 $self -> config(${$self -> config}{$self -> section});
83  
84 } # End of read.
85  
86 # --------------------------------------------------
87  
88 1 1;
89  
90 =pod
91  
92 =head1 NAME
93  
94 Benchmark::Featureset::LocaleCountry::Config - Compare Locale::Codes, Locale::Country::Multilingual, WWW::Scraper::Wikipedia::ISO3166, etc
95  
96 =head1 Synopsis
97  
98 See L<Benchmark::Featureset::LocaleCountry>.
99  
100 =head1 Description
101  
102 L<Benchmark::Featureset::LocaleCountry> provides subcountry names in their native scripts.
103  
104 =head1 Methods
105  
106 =head2 init()
107  
108 For use by subclasses.
109  
110 Sets default values for object attributes.
111  
112 =head2 new()
113  
114 For use by subclasses.
115  
116 =head2 read()
117  
118 read() is called by new(). It does the actual reading of the config file.
119  
120 If the file can't be read, die is called.
121  
122 The path to the config file is determined by:
123  
124 Path::Class::file(File::HomeDir -> my_dist_config('Benchmark-Featureset-LocaleCountry'), '.htbenchmark.featureset.localecountry.conf');
125  
126 During installation, you should have run scripts/copy.config.pl, which uses the same code, to move the config file
127 from the config/ directory in the disto into an OS-dependent directory.
128  
129 The run-time code uses this module to look in the same directory as used by scripts/copy.config.pl.
130  
131 =head1 Support
132  
133 Email the author, or log a bug on RT:
134  
135 L<https://rt.cpan.org/Public/Dist/Display.html?Name=Benchmark::Featureset::LocaleCountry>.
136  
137 =head1 Author
138  
139 L<Benchmark::Featureset::LocaleCountry> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2011.
140  
141 Home page: L<http://savage.net.au/index.html>.
142  
143 =head1 Copyright
144  
145 Australian copyright (c) 2011, Ron Savage.
146  
147 All Programs of mine are 'OSI Certified Open Source Software';
148 you can redistribute them and/or modify them under the terms of
149 The Artistic License, a copy of which is available at:
150 http://www.opensource.org/licenses/index.html
151  
152 =cut
↑ Summary LocaleCountry.pm »