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