line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Labyrinth::Phrasebook; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
2544
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
222
|
|
4
|
6
|
|
|
6
|
|
24
|
use strict; |
|
6
|
|
|
|
|
8
|
|
|
6
|
|
|
|
|
315
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
21
|
use vars qw($VERSION); |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
307
|
|
7
|
|
|
|
|
|
|
$VERSION = '5.30'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Labyrinth::Phrasebook - Phrasebook Manager for Labyrinth |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Labyrinth::Phrasebook; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $pb = Labyrinth::Phrasebook->new($phrasebook); |
18
|
|
|
|
|
|
|
$pb->load($dictionary); |
19
|
|
|
|
|
|
|
my $result = $pb->get($entry); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 DESCRIPTION |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Using L, this package acts as a simple wrapper for the |
24
|
|
|
|
|
|
|
Labyrinth framework. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# ------------------------------------- |
29
|
|
|
|
|
|
|
# Library Modules |
30
|
|
|
|
|
|
|
|
31
|
6
|
|
|
6
|
|
2853
|
use Data::Phrasebook; |
|
6
|
|
|
|
|
7815
|
|
|
6
|
|
|
|
|
971
|
|
32
|
6
|
|
|
6
|
|
29
|
use Labyrinth::Audit; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
806
|
|
33
|
6
|
|
|
6
|
|
2384
|
use Labyrinth::Writer; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# ------------------------------------- |
36
|
|
|
|
|
|
|
# Variables |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my %pbcache; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# ------------------------------------- |
41
|
|
|
|
|
|
|
# The Public Interface Subs |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 FUNCTIONS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 Constructor |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=over 4 |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item new() |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Create a new Phrasebook object. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=back |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub new { |
58
|
|
|
|
|
|
|
my ($self, $phrasebook, $dict) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Croak("Cannot read configuration file [$phrasebook]\n") unless(-r $phrasebook); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
my $pb = Data::Phrasebook->new( |
63
|
|
|
|
|
|
|
class => 'Plain', |
64
|
|
|
|
|
|
|
loader => 'Ini', |
65
|
|
|
|
|
|
|
file => $phrasebook |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Croak("Cannot access configuration file [$phrasebook]\n") unless($pb); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# set dictionary if not using default |
71
|
|
|
|
|
|
|
$pb->dict($dict) if($dict); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# set parameter pattern |
74
|
|
|
|
|
|
|
$pb->delimiters( qr{ \$(\w+) }x, 1 ); |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# create an attributes hash |
77
|
|
|
|
|
|
|
my $atts = { 'pb' => $pb }; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# create the object |
80
|
|
|
|
|
|
|
bless $atts, $self; |
81
|
|
|
|
|
|
|
return $atts; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 Methods |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=over 4 |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item load |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Reset primary dictionary. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub load { |
95
|
|
|
|
|
|
|
my ($self, $section) = @_; |
96
|
|
|
|
|
|
|
$self->{pb}->dict( $section ) if($section); |
97
|
|
|
|
|
|
|
return $self->{pb}->dict; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item get |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Gets an entry from the current section or from the default section if |
103
|
|
|
|
|
|
|
entry doesn't exist in the current section. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=cut |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub get { |
108
|
|
|
|
|
|
|
my ($self, $key, $hash) = @_; |
109
|
|
|
|
|
|
|
my $crypt = join('', map { "$_=$hash->{$_}" } grep {$hash->{$_}} keys %$hash); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
return $pbcache{$key}{$crypt} if($pbcache{$key}{$crypt}); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
my $val = $self->{pb}->fetch( $key, $hash ); |
114
|
|
|
|
|
|
|
Croak("Unknown key phrase [$key]\n") unless($val); |
115
|
|
|
|
|
|
|
$val =~ s/\n|\t/ /sg; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
# # parse any given parameters |
118
|
|
|
|
|
|
|
# if($hash) { |
119
|
|
|
|
|
|
|
# for my $name (keys %$hash) { |
120
|
|
|
|
|
|
|
# LogDebug("get: name=[$name], value=[$hash->{$name}]"); |
121
|
|
|
|
|
|
|
# $hash->{$name} ||= ''; |
122
|
|
|
|
|
|
|
# $val =~ s/\$$name/$hash->{$name}/g; |
123
|
|
|
|
|
|
|
# } |
124
|
|
|
|
|
|
|
# } |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
# $val =~ s/\$\w+//g; # remove unparsed parameters |
127
|
|
|
|
|
|
|
$pbcache{$key}{$crypt} = $val; |
128
|
|
|
|
|
|
|
return $val; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub DESTROY {1} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__END__ |