line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Religion::Bible::Regex::Config; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
58378
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
189
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
220
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1832
|
use version; our $VERSION = '0.61'; |
|
1
|
|
|
|
|
7379
|
|
|
1
|
|
|
|
|
8
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
1007
|
use YAML::Loader; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Input files are assumed to be in the UTF-8 strict character encoding. |
12
|
|
|
|
|
|
|
#use utf8; |
13
|
|
|
|
|
|
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
|
|
|
|
|
|
my $class = shift; |
17
|
|
|
|
|
|
|
my $self = {}; |
18
|
|
|
|
|
|
|
my $config = shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
bless ($self, $class); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
croak "Religion::Bible::Regex::Config must be initialize with a string which containing either a the location of a YAML file or actual YAML" unless (defined($config)); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# If $config is a file that exists |
25
|
|
|
|
|
|
|
# Crud method for testing that this is not YAML --> m/\n/ == 0 |
26
|
|
|
|
|
|
|
if ($config =~ m/\n/ == 0 && -e $config) { |
27
|
|
|
|
|
|
|
$self->{config} = $self->_read_yaml_file($config); |
28
|
|
|
|
|
|
|
} else { |
29
|
|
|
|
|
|
|
my $yaml_loader = YAML::Loader->new(); |
30
|
|
|
|
|
|
|
$self->{config} = $yaml_loader->load($config); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub get { |
37
|
|
|
|
|
|
|
my $self = shift; |
38
|
|
|
|
|
|
|
my @keys = @_; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $ret = $self->{config}; |
41
|
|
|
|
|
|
|
foreach my $key (@keys) { |
42
|
|
|
|
|
|
|
# carp "Configuration not found: {$key}" unless defined($ret->{$key}); |
43
|
|
|
|
|
|
|
$ret = $ret->{$key}; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
return $ret; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_or_undef { |
49
|
|
|
|
|
|
|
my $self = shift; |
50
|
|
|
|
|
|
|
my @keys = @_; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $ret = $self->{config}; |
53
|
|
|
|
|
|
|
foreach my $key (@keys) { |
54
|
|
|
|
|
|
|
return unless defined($ret->{$key}); |
55
|
|
|
|
|
|
|
$ret = $ret->{$key}; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
return $ret; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# These getter functions are very important to have right. |
62
|
|
|
|
|
|
|
sub get_bookname_configurations { |
63
|
|
|
|
|
|
|
return shift->{'config'}{'books'}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub get_search_configurations { |
67
|
|
|
|
|
|
|
return shift->{'config'}{'regex'}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub get_formatting_configurations { |
71
|
|
|
|
|
|
|
return shift->{'config'}{'reference'}; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub get_versification_configurations { |
75
|
|
|
|
|
|
|
return shift->{'config'}{'versification'}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _read_yaml_file { |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
my $path_to_config_file = shift; |
81
|
|
|
|
|
|
|
my $config; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $yaml_loader = YAML::Loader->new(); |
84
|
|
|
|
|
|
|
my $yaml_text; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# Vous ouvrez le fichier de configuration |
87
|
|
|
|
|
|
|
if(open(*CONFIG, "<:encoding(UTF-8)", $path_to_config_file)) { |
88
|
|
|
|
|
|
|
{ |
89
|
|
|
|
|
|
|
local( $/, *FH ); |
90
|
|
|
|
|
|
|
$yaml_text = ; # slurp it |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
$config = $yaml_loader->load($yaml_text); |
93
|
|
|
|
|
|
|
close (CONFIG); |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
return $config; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
99
|
|
|
|
|
|
|
__END__ |