line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
=head1 NAME |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
Bio::Polloc::TypingIO::cfg - Implementation of Bio::Polloc::TypingIO for .cfg files |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 DESCRIPTION |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Reads .cfg files (a.k.a. .bme files) and produces a L<Bio::Polloc::TypingIO> |
8
|
|
|
|
|
|
|
object. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 AUTHOR - Luis M. Rodriguez-R |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Email lmrodriguezr at gmail dot com |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 IMPLEMENTS OR EXTENDS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=over |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=item * |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
L<Bio::Polloc::TypingIO> |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=back |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
package Bio::Polloc::TypingIO::cfg; |
27
|
2
|
|
|
2
|
|
11
|
use base qw(Bio::Polloc::TypingIO); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
152
|
|
28
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
61
|
|
29
|
2
|
|
|
2
|
|
1215
|
use Bio::Polloc::Polloc::Config; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
108
|
|
30
|
2
|
|
|
2
|
|
1456
|
use Bio::Polloc::TypingI; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
1351
|
|
31
|
|
|
|
|
|
|
our $VERSION = 1.0503; # [a-version] from Bio::Polloc::Polloc::Version |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 APPENDIX |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Methods provided by the package |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Generic initialization method. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head3 Arguments |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item * |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Any parameter accepted by L<Bio::Polloc::TypingIO>. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item * |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Any parameter accepted by L<Bio::Polloc::Polloc::Config>. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=back |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub new { |
61
|
0
|
|
|
0
|
1
|
0
|
my($caller,@args) = @_; |
62
|
0
|
|
|
|
|
0
|
my $self = $caller->SUPER::new(@args); |
63
|
0
|
|
|
|
|
0
|
$self->_initialize(@args); |
64
|
0
|
|
|
|
|
0
|
return $self; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 read |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
Configures and parses the file. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=cut |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub read { |
74
|
2
|
|
|
2
|
1
|
7
|
my($self,@args) = @_; |
75
|
2
|
|
|
|
|
5
|
$self->_cfg->_register_handle_function( |
76
|
|
|
|
|
|
|
-obj=>$self, |
77
|
|
|
|
|
|
|
-fun=>"_parse_eval", |
78
|
|
|
|
|
|
|
-token=>".typing.eval"); |
79
|
2
|
|
|
|
|
6
|
$self->_cfg->parse(@args); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 value |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Sets/gets a stored value. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head3 Arguments |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=over |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item -key |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
The key. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item -value |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
The value (if any). |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item alert |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
If true, alerts if the key is not set. |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head3 Returns |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
The value (mix). |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub value { |
111
|
8
|
|
|
8
|
1
|
15
|
my($self,@args) = @_; |
112
|
8
|
|
|
|
|
45
|
my($key,$value,$alert) = $self->_rearrange([qw(KEY VALUE ALERT)], @args); |
113
|
8
|
50
|
|
|
|
22
|
$self->_cfg->_save(-key=>$key, -value=>$value, -space=>"rule") if $value; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Search first in the Typing space |
116
|
8
|
|
|
|
|
17
|
$value = $self->_cfg->value(-key=>$key, -space=>"typing", -noalert=>1); |
117
|
8
|
50
|
|
|
|
46
|
return $value if defined $value; |
118
|
|
|
|
|
|
|
# Search in the root space otherwise |
119
|
0
|
|
|
|
|
0
|
return $self->_cfg->value(-key=>$key, -space=>".", -noalert=>!$alert); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 INTERNAL METHODS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Methods intended to be used only within the scope of Bio::Polloc::* |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 _cfg |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Sets/gets the L<Bio::Polloc::Polloc::Config> main object. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head3 Throws |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
L<Bio::Polloc::Polloc::Error> if the object is not of the proper class. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=cut |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub _cfg { |
137
|
18
|
|
|
18
|
|
25
|
my($self,$value) = @_; |
138
|
18
|
100
|
|
|
|
40
|
$self->{'_cfg_obj'} = $value if $value; |
139
|
18
|
50
|
|
|
|
39
|
return unless $self->{'_cfg_obj'}; |
140
|
18
|
50
|
|
|
|
68
|
$self->{'_cfg_obj'}->isa('Bio::Polloc::Polloc::Config') or |
141
|
|
|
|
|
|
|
$self->throw("Unexpected type of cfg object", $self->{'_cfg_obj'}); |
142
|
18
|
|
|
|
|
82
|
return $self->{'_cfg_obj'}; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head2 _parse_eval |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
sub _parse_eval { |
150
|
2
|
|
|
2
|
|
6
|
my($self, $body,$defaults) = @_; |
151
|
2
|
50
|
|
|
|
6
|
$self->throw("Trying to define Bio::Polloc::TypingI object, but no type given") |
152
|
|
|
|
|
|
|
unless defined $body; |
153
|
2
|
|
|
|
|
12
|
$body =~ s/^\s*(.*)\s*$/$1/; |
154
|
2
|
|
|
|
|
8
|
$body =~ s/^'\s*(.*)\s*'$/$1/; |
155
|
2
|
50
|
|
|
|
15
|
$body =~ m/^[a-z]+(::[a-z]+)*$/i |
156
|
|
|
|
|
|
|
or $self->throw("Bad format for the body of .typing.eval, ". |
157
|
|
|
|
|
|
|
"expecting the type of typing", $body, |
158
|
|
|
|
|
|
|
'Bio::Polloc::Polloc::ParsingException'); |
159
|
|
|
|
|
|
|
# Read arguments |
160
|
2
|
|
|
|
|
5
|
my %args = (); |
161
|
2
|
|
|
|
|
7
|
for my $k ($self->_cfg->all_keys('.typing')){ |
162
|
8
|
|
|
|
|
25
|
(my $name = $k) =~ s/^\.typing\.//; |
163
|
8
|
|
|
|
|
23
|
$name =~ s/^(?!-)/-/; |
164
|
8
|
|
|
|
|
19
|
$args{$name} = $self->value($k); |
165
|
|
|
|
|
|
|
} |
166
|
2
|
|
|
|
|
6
|
$args{'-type'} = $body; |
167
|
2
|
|
|
|
|
18
|
$self->typing(Bio::Polloc::TypingI->new(%args)); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 _parse_cfg |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub _parse_cfg { |
175
|
2
|
|
|
2
|
|
6
|
my($self,@args) = @_; |
176
|
2
|
|
|
|
|
19
|
$self->_cfg( Bio::Polloc::Polloc::Config->new(-noparse=>1, @args) ); |
177
|
2
|
|
|
|
|
5
|
$self->_cfg->spaces(".typing"); |
178
|
2
|
|
|
|
|
6
|
$self->read(@args); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 _initialize |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub _initialize { |
186
|
2
|
|
|
2
|
|
7
|
my($self,@args) = @_; |
187
|
2
|
|
|
|
|
8
|
$self->_parse_cfg(@args); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
1; |