File Coverage

blib/lib/Siebel/Srvrmgr/ListParser/Output/Tabular/ListParams.pm
Criterion Covered Total %
statement 53 54 98.1
branch 16 18 88.8
condition n/a
subroutine 7 7 100.0
pod 1 1 100.0
total 77 80 96.2


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr::ListParser::Output::Tabular::ListParams;
2              
3 6     6   7219 use Moose 2.0401;
  6         149  
  6         57  
4 6     6   54204 use namespace::autoclean 0.13;
  6         181  
  6         59  
5 6     6   699 use Carp;
  6         24  
  6         4341  
6             our $VERSION = '0.29'; # VERSION
7              
8             =pod
9              
10             =head1 NAME
11              
12             Siebel::Srvrmgr::ListParser::Output::Tabular::ListParams - subclass to parse output of the command C<list comp params>.
13              
14             =cut
15              
16             extends 'Siebel::Srvrmgr::ListParser::Output::Tabular';
17              
18             =pod
19              
20             =head1 SYNOPSIS
21              
22             use Siebel::Srvrmgr::ListParser::Output::Tabular::ListParams;
23              
24             my $comp_params = Siebel::Srvrmgr::ListParser::Output::Tabular::ListParams->new({ data_type => 'list_params',
25             raw_data => \@com_data,
26             cmd_line => 'list params for server XXXX component YYYY'});
27             my $server_params = Siebel::Srvrmgr::ListParser::Output::Tabular::ListParams->new({ data_type => 'list_params',
28             raw_data => \@server_data,
29             cmd_line => 'list params for server XXXX'});
30              
31             =head1 DESCRIPTION
32              
33             This module parses the output of the command C<list comp params>. Beware that those parameters may be of the server if a component alias is omitted from
34             the command line.
35              
36             This is most probably the default configuration of the output:
37              
38             srvrmgr> configure list params
39             PA_ALIAS (76): Parameter alias
40             PA_VALUE (256): Parameter value
41             PA_DATATYPE (31): Parameter value datatype
42             PA_SCOPE (31): Parameter level
43             PA_SUBSYSTEM (31): Parameter subsystem
44             PA_SETLEVEL (31): Internal level at which value was set
45             PA_DISP_SETLEVEL (61): Display level at which value was set (translatable)
46             PA_EFF_NEXT_TASK (2): Parameter effective at next task (bool)
47             PA_EFF_CMP_RSTRT (2): Parameter effective at component restart (bool)
48             PA_EFF_SRVR_RSTRT (2): Parameter effective at server restart (bool)
49             PA_REQ_COMP_RCFG (2): Parameter requires component reconfiguration (bool)
50             PA_NAME (76): Parameter name
51              
52             This is what the parser of this class will expected to find:
53              
54             srvrmgr> configure list params
55             PA_ALIAS (76): Parameter alias
56             PA_VALUE (256): Parameter value
57             PA_DATATYPE (31): Parameter value datatype
58             PA_SCOPE (31): Parameter level
59             PA_SUBSYSTEM (31): Parameter subsystem
60             PA_SETLEVEL (31): Internal level at which value was set
61             PA_DISP_SETLEVEL (61): Display level at which value was set (translatable)
62             PA_EFF_NEXT_TASK (16): Parameter effective at next task (bool)
63             PA_EFF_CMP_RSTRT (16): Parameter effective at component restart (bool)
64             PA_EFF_SRVR_RSTRT (17): Parameter effective at server restart (bool)
65             PA_REQ_COMP_RCFG (16): Parameter requires component reconfiguration (bool)
66             PA_NAME (76): Parameter name
67              
68             The C<data_parsed> attribute will return the a data estructure like this:
69              
70             'data_parsed' => {
71             'Parameter1' => {
72             'PA_NAME' => 'Private key file name',
73             'PA_DATATYPE' => 'String',
74             'PA_SCOPE' => 'Subsystem',
75             'PA_VALUE' => '',
76             'PA_EFF_NEXT_TASK' => '',
77             'PA_EFF_CMP_RSTRT' => '',
78             'PA_EFF_SRVR_RSTRT' => '',
79             'PA_REQ_COMP_RCFG' => '',
80             'PA_ALIAS' => 'Parameter1',
81             'PA_SETLEVEL' => 'SIS_NEVER_SET',
82             'PA_DISP_SETLEVEL' => 'SIS_NEVER_SET',
83             'PA_SUBSYSTEM' => 'Networking'
84             },
85             'Parameter2' => {
86             'PA_NAME' => 'Private key file name',
87             'PA_DATATYPE' => 'String',
88             'PA_SCOPE' => 'Subsystem',
89             'PA_VALUE' => '',
90             'PA_EFF_NEXT_TASK' => '',
91             'PA_EFF_CMP_RSTRT' => '',
92             'PA_EFF_SRVR_RSTRT' => '',
93             'PA_REQ_COMP_RCFG' => '',
94             'PA_ALIAS' => 'Parameter2',
95             'PA_SETLEVEL' => 'SIS_NEVER_SET',
96             'PA_DISP_SETLEVEL' => 'SIS_NEVER_SET',
97             'PA_SUBSYSTEM' => 'Networking'
98             },
99             # N parameters
100             }
101              
102             So far there is no method implemented that would return a parameter name and it's properties, it's necessary to access the hashes directly.
103              
104             =head1 ATTRIBUTES
105              
106             Additionally to the parent class, these attributes are all generated from the command line given to new, if available.
107              
108             Since they are set automatically, none is required. It is assumed that if a attribute is set to C<undef>, there are no corresponding options in the C<list parameter> command.
109              
110             All these attributes are read-only.
111              
112             =head2 server
113              
114             An string representing the server from the command executed.
115              
116             =cut
117              
118             has server =>
119             ( isa => 'Str', is => 'ro', writer => '_set_server', reader => 'get_server' );
120              
121             =pod
122              
123             =head2 comp_alias
124              
125             An string of the component alias respective to the command executed.
126              
127             =cut
128              
129             has comp_alias => (
130             isa => 'Str',
131             is => 'ro',
132             writer => '_set_comp_alias',
133             reader => 'get_comp_alias'
134             );
135              
136             =head2 named_subsys
137              
138             A string representing the named subsystem used in the command.
139              
140             =cut
141              
142             has named_subsys => (
143             isa => 'Str',
144             is => 'ro',
145             writer => '_set_named_subsys',
146             reader => 'get_named_subsys'
147             );
148              
149             =head2 task
150              
151             A integer representing the task number used in the executed command.
152              
153             =cut
154              
155             has task =>
156             ( isa => 'Int', is => 'ro', writer => '_set_task', reader => 'get_task' );
157              
158             =head2 param
159              
160             A string representing the specific parameter requested in the executed command.
161              
162             =cut
163              
164             has param =>
165             ( isa => 'Str', is => 'ro', writer => '_set_param', reader => 'get_param' );
166              
167             =pod
168              
169             =head2 BUILD
170              
171             Set values for some class attributes depending on the command line used during object creation.
172              
173             =cut
174              
175             sub BUILD {
176              
177 37     37 1 140 my $self = shift;
178              
179 37 50       1580 if ( defined( $self->get_cmd_line() ) ) {
180              
181 37         1419 my @tokens = split( /\s/, $self->get_cmd_line );
182 37         207 my $comp_regex = qr/^comp(onent)?$/;
183 37         158 my $param_regex = qr/param(eter)?s?/;
184              
185 37         180 while ( my $token = shift(@tokens) ) {
186              
187             SWITCH: {
188              
189 108 100       216 if ( $token =~ $comp_regex ) {
  108         547  
190              
191 20         1055 $self->_set_comp_alias( shift(@tokens) );
192 20         949 next;
193              
194             }
195              
196 88 100       272 if ( $token eq 'server' ) {
197              
198 4         191 $self->_set_server( shift(@tokens) );
199 4         14 next;
200              
201             }
202              
203 84 100       240 if ( $token eq 'task' ) {
204              
205 2         105 $self->_set_task( shift(@tokens) );
206 2         92 next;
207              
208             }
209              
210 82 100       476 if ( $token =~ $param_regex ) {
211              
212 37         123 my $next = shift(@tokens);
213              
214 37 100       718 next unless ( defined($next) );
215              
216 24 100       113 if ( $next eq 'for' ) {
217              
218 20         89 next;
219              
220             }
221             else {
222              
223 4         197 $self->_set_param($next);
224 4         18 next;
225              
226             }
227              
228             }
229              
230 45 100       220 if ( $token eq 'named' ) {
231              
232 2         4 shift(@tokens); # remove the subsystem string
233 2         72 $self->_set_named_subsys( shift(@tokens) );
234 2         109 next;
235              
236             }
237              
238             }
239              
240             }
241              
242             }
243              
244             }
245              
246             sub _build_expected {
247              
248 37     37   121 my $self = shift;
249              
250 37         1955 $self->_set_expected_fields(
251             [
252             'PA_ALIAS', 'PA_VALUE',
253             'PA_DATATYPE', 'PA_SCOPE',
254             'PA_SUBSYSTEM', 'PA_SETLEVEL',
255             'PA_DISP_SETLEVEL', 'PA_EFF_NEXT_TASK',
256             'PA_EFF_CMP_RSTRT', 'PA_EFF_SRVR_RSTRT',
257             'PA_REQ_COMP_RCFG', 'PA_NAME'
258             ]
259             );
260              
261             }
262              
263             sub _consume_data {
264              
265 20090     20090   42762 my $self = shift;
266 20090         35731 my $fields_ref = shift;
267 20090         34362 my $parsed_ref = shift;
268              
269 20090         933523 my $columns_ref = $self->get_expected_fields();
270              
271 20090 50       38028 if ( @{$fields_ref} ) {
  20090         50818  
272              
273 20090         43563 my $pa_alias = $fields_ref->[0];
274 20090         34828 my $list_len = scalar( @{$columns_ref} )
  20090         38841  
275             ; # safer to use the columns reference size if the output has some issue
276              
277 20090         54406 for ( my $i = 1 ; $i < $list_len ; $i++ )
278             { # starting from 1 to skip the field PA_ALIAS
279              
280 220990         665013 $parsed_ref->{$pa_alias}->{ $columns_ref->[$i] } =
281             $fields_ref->[$i];
282              
283             }
284              
285 20090         115470 return 1;
286              
287             }
288             else {
289              
290 0           return 0;
291              
292             }
293              
294             }
295              
296             =pod
297              
298             =head1 CAVEATS
299              
300             This class is capable to parse the output from C<list advanced params> but during tests it was identified that configuring output from C<list params> will not provided the expected
301             results. It was possible to parse the output without any configuration, but results may differ from version to version.
302              
303             =head1 SEE ALSO
304              
305             =over
306              
307             =item *
308              
309             L<Siebel::Srvrmgr::ListParser::Output::Tabular>
310              
311             =item *
312              
313             L<Moose>
314              
315             =item *
316              
317             L<Storable>
318              
319             =back
320              
321             =head1 AUTHOR
322              
323             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
324              
325             =head1 COPYRIGHT AND LICENSE
326              
327             This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
328              
329             This file is part of Siebel Monitoring Tools.
330              
331             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
332             it under the terms of the GNU General Public License as published by
333             the Free Software Foundation, either version 3 of the License, or
334             (at your option) any later version.
335              
336             Siebel Monitoring Tools is distributed in the hope that it will be useful,
337             but WITHOUT ANY WARRANTY; without even the implied warranty of
338             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
339             GNU General Public License for more details.
340              
341             You should have received a copy of the GNU General Public License
342             along with Siebel Monitoring Tools. If not, see L<http://www.gnu.org/licenses/>.
343              
344             =cut
345              
346 6     6   69 no Moose;
  6         18  
  6         42  
347             __PACKAGE__->meta->make_immutable;