File Coverage

blib/lib/Siebel/Srvrmgr/ListParser/Output/Enterprise.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 26 26 100.0


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr::ListParser::Output::Enterprise;
2              
3             =pod
4              
5             =head1 NAME
6              
7             Siebel::Srvrmgr::ListParser::Output::Enterprise - subclass that represents the initial information from a Siebel server when connected through srvrmgr program.
8              
9             =head1 SYNOPSIS
10              
11             See L<Siebel::Srvrmgr::ListParser::Output>.
12              
13             =cut
14              
15 7     7   7310 use Moose 2.0401;
  7         190  
  7         72  
16 7     7   46218 use Siebel::Srvrmgr::Regexes qw(CONN_GREET);
  7         22  
  7         571  
17 7     7   57 use Carp;
  7         25  
  7         566  
18 7     7   51 use List::Util 1.42 qw(sum);
  7         215  
  7         6034  
19              
20             extends 'Siebel::Srvrmgr::ListParser::Output';
21             our $VERSION = '0.29'; # VERSION
22              
23             =pod
24              
25             =head1 DESCRIPTION
26              
27             C<Siebel::Srvrmgr::ListParser::Output::Greetings> extends C<Siebel::Srvrmgr::ListParser::Output>.
28              
29             Normally this class would be created by L<Siebel::Srvrmgr::ListParser::OutputFactory> C<create> static method. See the automated tests for examples of direct
30             instatiation.
31              
32             It is possible to recover some useful information from the object methods but most of it is simple copyrigh information.
33              
34             =head1 ATTRIBUTES
35              
36             =head2 version
37              
38             A string that represents the version of the Siebel enterprise where the connection was stablished. This is a read-only attribute.
39              
40             =cut
41              
42             has 'version' => (
43             is => 'ro',
44             isa => 'Str',
45             reader => 'get_version',
46             writer => '_set_version'
47             );
48              
49             =pod
50              
51             =head2 patch
52              
53             A string that represents the patch version of the Siebel enterprise where the connection was stablished. This is a read-only attribute.
54              
55             =cut
56              
57             has 'patch' =>
58             ( is => 'ro', isa => 'Int', reader => 'get_patch', writer => '_set_patch' );
59              
60             =pod
61              
62             =head2 copyright
63              
64             An array reference that represents the copyright information of the Siebel enterprise where the connection was stablished. This is a read-only attribute.
65              
66             =cut
67              
68             has 'copyright' => (
69             is => 'ro',
70             isa => 'ArrayRef[Str]',
71             reader => 'get_copyright'
72             );
73              
74             =pod
75              
76             =head2 total_servers
77              
78             A integer that represents the total number of servers configured in the enterprise where the connection was stablished. This is a read-only attribute.
79              
80             =cut
81              
82             has 'total_servers' => (
83             is => 'ro',
84             isa => 'Int',
85             reader => 'get_total_servers',
86             writer => '_set_total_servers'
87             );
88              
89             =pod
90              
91             =head2 total_connected
92              
93             A integer that represents the total number of servers available in the enterprise where the connection was stablished. This is a read-only attribute.
94              
95             =cut
96              
97             has 'total_connected' => (
98             is => 'ro',
99             isa => 'Int',
100             reader => 'get_total_conn',
101             writer => '_set_total_conn'
102             );
103              
104             =pod
105              
106             =head2 help
107              
108             A string representing how to invoke online help within C<srvrmgr> program. This is a read-only attribute.
109              
110             =cut
111              
112             has 'help' => (
113             is => 'ro',
114             isa => 'Str',
115             reader => 'get_help',
116             writer => '_set_help'
117             );
118              
119             =pod
120              
121             =head1 METHODS
122              
123             See L<Siebel::Srvrmgr::ListParser::Output> class for inherited methods.
124              
125             =head2 get_version
126              
127             Returns a string as the value of version attribute.
128              
129             =head2 get_patch
130              
131             Returns a string as the value of patch attribute.
132              
133             =head2 get_copyright
134              
135             Returns a string as the value of copyright attribute.
136              
137             =head2 get_total_servers
138              
139             Returns a integer as the value of total_servers attribute.
140              
141             =head2 get_total_conn
142              
143             Returns a integer as the value of total_connected attribute.
144              
145             =head2 parse
146              
147             This method overrides the superclass.
148              
149             =cut
150              
151             override 'parse' => sub {
152              
153             my $self = shift;
154              
155             my $data_ref = $self->get_raw_data();
156              
157             my %data_parsed;
158              
159             #Copyright (c) 2001 Siebel Systems, Inc. All rights reserved.
160             my $copyright_regex = qr/^Copyright\s\(c\)/;
161             my $more_copyright = qr/^[\w\(]+/;
162             my $help_regex = qr/^Type\s\"help\"/;
163              
164             #Connected to 1 server(s) out of a total of 1 server(s) in the enterprise
165             #Connected to 2 server(s) out of a total of 2 server(s) in the enterprise
166             my $connected_regex = qr/^Connected\sto\s\d+\sserver\(s\)/;
167              
168             my %check = (
169             conn_greet => 0,
170             copyright => 0,
171             help => 0,
172             connected => 0,
173             more_copyright => 0
174             );
175              
176             foreach my $line ( @{$data_ref} ) {
177              
178             chomp($line);
179              
180             SWITCH: {
181              
182             if ( $line eq '' ) {
183              
184             # do nothing
185             last SWITCH;
186             }
187              
188             if ( $line =~ CONN_GREET ) {
189              
190             #Siebel Enterprise Applications Siebel Server Manager, Version 7.5.3 [16157] LANG_INDEPENDENT
191             my @words = split( /\s/, $line );
192              
193             $self->_set_version( $words[7] );
194             $data_parsed{version} = $words[7];
195              
196             $words[8] =~ tr/[]//d;
197             $self->_set_patch( $words[8] );
198             $data_parsed{patch} = $words[8];
199             $check{conn_greet} = 1;
200             last SWITCH;
201              
202             }
203              
204             if ( $line =~ $copyright_regex ) {
205              
206             $self->_set_copyright($line);
207             $data_parsed{copyright} = $line;
208             $check{copyright} = 1;
209             last SWITCH;
210              
211             }
212              
213             if ( $line =~ $help_regex ) {
214              
215             $self->_set_help($line);
216             $data_parsed{help} = $line;
217             $check{help} = 1;
218             last SWITCH;
219              
220             }
221              
222             if ( $line =~ $connected_regex ) {
223              
224             my @words = split( /\s/, $line );
225              
226             $self->_set_total_servers( $words[9] );
227             $self->_set_total_conn( $words[2] );
228             $data_parsed{total_servers} = $words[9];
229             $data_parsed{total_conn} = $words[2];
230             $check{connected} = 1;
231             last SWITCH;
232              
233             }
234              
235             if ( $line =~ $more_copyright ) {
236              
237             $self->_set_copyright($line) if ( $check{copyright} );
238             $data_parsed{copyright} = $line;
239             $check{more_copyright} = 1;
240             last SWITCH;
241              
242             }
243             else {
244              
245             confess 'Do not know how to deal with line content "' . $line
246             . '"';
247              
248             }
249              
250             }
251              
252             }
253              
254             $self->set_data_parsed( \%data_parsed );
255             $self->set_raw_data( [] );
256              
257             if ( ( keys(%check) ) == ( sum( values(%check) ) ) ) {
258              
259             return 1;
260              
261             }
262             else {
263              
264             foreach my $key ( keys(%check) ) {
265              
266             warn "$key was not matched" unless ( $check{$key} );
267              
268             }
269             return 0;
270              
271             }
272              
273             };
274              
275             =pod
276              
277             =head2 _set_copyright
278              
279             "Private" method to set the copyright information.
280              
281             =cut
282              
283             sub _set_copyright {
284              
285 167     167   331 my $self = shift;
286 167         301 my $line = shift;
287              
288 167         316 push( @{ $self->{copyright} }, $line );
  167         502  
289              
290 167         360 return 1;
291              
292             }
293              
294             =pod
295              
296             =head1 CAVEATS
297              
298             Beware that the parse method is called automatically as soon as the object is created.
299              
300             =head1 SEE ALSO
301              
302             =over 2
303              
304             =item *
305              
306             L<Siebel::Srvrmgr::Regexes>
307              
308             =item *
309              
310             L<Siebel::Srvrmgr::ListParser::Output>
311              
312             =back
313              
314             =head1 AUTHOR
315              
316             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
317              
318             =head1 COPYRIGHT AND LICENSE
319              
320             This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
321              
322             This file is part of Siebel Monitoring Tools.
323              
324             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
325             it under the terms of the GNU General Public License as published by
326             the Free Software Foundation, either version 3 of the License, or
327             (at your option) any later version.
328              
329             Siebel Monitoring Tools is distributed in the hope that it will be useful,
330             but WITHOUT ANY WARRANTY; without even the implied warranty of
331             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
332             GNU General Public License for more details.
333              
334             You should have received a copy of the GNU General Public License
335             along with Siebel Monitoring Tools. If not, see L<http://www.gnu.org/licenses/>.
336              
337             =cut
338              
339             __PACKAGE__->meta->make_immutable;
340 7     7   75 no Moose;
  7         26  
  7         58