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