line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package oEdtk::Dict; |
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1155
|
use Config::IniFiles; |
|
1
|
|
|
|
|
34801
|
|
|
1
|
|
|
|
|
46
|
|
6
|
1
|
|
|
1
|
|
12
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
553
|
|
7
|
|
|
|
|
|
|
our $VERSION = 0.7012; |
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Création d'un dictionnaire à partir d'un fichier INI. |
11
|
|
|
|
|
|
|
sub new { |
12
|
2
|
|
|
2
|
0
|
7
|
my ($class, $path, $options) = @_; |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
50
|
|
|
18
|
my $invert = $options->{'invert'} || 0; |
15
|
2
|
|
50
|
|
|
12
|
my $section = $options->{'section'} || 'DEFAULT'; |
16
|
2
|
|
50
|
|
|
12
|
my $ignore_case = $options->{'ignore_case'} || 1; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# warn "INFO : Path EDTK_DICO >$path< \n"; |
19
|
2
|
|
|
|
|
28
|
tie my %ini, 'Config::IniFiles', |
20
|
|
|
|
|
|
|
(-file => $path, -default => $section); |
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
|
|
284
|
my $dico = $ini{$section}; |
23
|
2
|
50
|
|
|
|
38
|
if ($invert) { |
24
|
|
|
|
|
|
|
# Inversion du hash. |
25
|
0
|
|
|
|
|
0
|
my %tr = (); |
26
|
0
|
|
|
|
|
0
|
while (my ($key, $val) = each %$dico) { |
27
|
0
|
0
|
|
|
|
0
|
if (ref($val) eq 'ARRAY') { |
28
|
0
|
|
|
|
|
0
|
$tr{$_} = $key foreach @$val; |
29
|
|
|
|
|
|
|
} else { |
30
|
0
|
|
|
|
|
0
|
$tr{$val} = $key; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
0
|
|
|
|
|
0
|
$dico = \%tr; |
34
|
|
|
|
|
|
|
} |
35
|
2
|
50
|
|
|
|
7
|
if ($ignore_case) { |
36
|
2
|
|
|
|
|
5
|
my $dico2 = {}; |
37
|
2
|
|
|
|
|
12
|
while (my ($key, $val) = each %$dico) { |
38
|
0
|
|
|
|
|
0
|
$dico2->{lc($key)} = $val; |
39
|
|
|
|
|
|
|
} |
40
|
2
|
|
|
|
|
5
|
$dico = $dico2; |
41
|
|
|
|
|
|
|
} |
42
|
2
|
|
|
|
|
9
|
my $self = { |
43
|
|
|
|
|
|
|
ignore_case => $ignore_case, |
44
|
|
|
|
|
|
|
dico => $dico |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# warn "INFO : objet Dict $class $self ($section $path) créé...\n"; |
48
|
2
|
|
|
|
|
19
|
return bless $self, $class; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub translate { |
53
|
|
|
|
|
|
|
# passer en option 'check' pour demander une vérification de la présence de la valeur dans le dictionnaire |
54
|
|
|
|
|
|
|
# si la valeur est absente du dictionnaire, retourne 'undef' |
55
|
0
|
|
|
0
|
0
|
|
my ($self, $word, $check) = @_; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $key = $word; |
58
|
0
|
0
|
|
|
|
|
if ($self->{'ignore_case'}) { |
59
|
0
|
|
|
|
|
|
$key = lc($key); |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
my $val = $self->{'dico'}->{$key}; |
62
|
0
|
0
|
0
|
|
|
|
if (!$check && !defined($val)) { |
63
|
0
|
|
|
|
|
|
$val = $word; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return $val; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub substitue { |
71
|
0
|
|
|
0
|
0
|
|
my ($self, $var) = @_; |
72
|
|
|
|
|
|
|
# warn "DEBUG: Dict::substitute value = '$var'\n"; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
0
|
|
|
|
if (defined($var) && length($var) > 0) { |
75
|
0
|
|
|
|
|
|
while (my ($key, $val) = each %{$self->{'dico'}}) { |
|
0
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$var =~s/$key/$val/ig; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# warn "DEBUG: Dict::substitute value = '$var'\n"; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return $var ; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
1; |