File Coverage

blib/lib/Siebel/Srvrmgr/ListParser/Output/LoadPreferences.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr::ListParser::Output::LoadPreferences;
2              
3             =pod
4              
5             =head1 NAME
6              
7             Siebel::Srvrmgr::ListParser::Output::LoadPreferences - subclass to parse load preferences command.
8              
9             =cut
10              
11 7     7   14723 use Moose 2.0401;
  7         202  
  7         81  
12 7     7   74897 use Siebel::Srvrmgr::Regexes qw(LOAD_PREF_RESP LOAD_PREF_CMD);
  7         22  
  7         612  
13 7     7   61 use namespace::autoclean 0.13;
  7         200  
  7         70  
14 7     7   901 use Carp;
  7         20  
  7         3799  
15              
16             extends 'Siebel::Srvrmgr::ListParser::Output';
17             our $VERSION = '0.29'; # VERSION
18              
19             =pod
20              
21             =head1 SYNOPSIS
22              
23             See L<Siebel::Srvrmgr::ListParser::Output> for example.
24              
25             =head1 DESCRIPTION
26              
27             This class is a subclass of L<Siebel::Srvrmgr::ListParser::Output>. In truth, this is not a parser for a C<list> command, but since the usage of
28             C<load preferences> is strongly recommended, this subclass was added to enable usage in L<Siebel::Srvrmgr::Daemon::Action> subclasses.
29              
30             =head1 ATTRIBUTES
31              
32             =head2 location
33              
34             A string of location of the preferences file returned by the C<load preferences> command.
35              
36             =cut
37              
38             has 'location' => (
39             is => 'rw',
40             isa => 'Str',
41             reader => 'get_location',
42             writer => 'set_location'
43             );
44              
45             =pod
46              
47             =head1 METHODS
48              
49             =head2 get_location
50              
51             Returns the C<location> attribute.
52              
53             =head2 set_location
54              
55             Set the C<location> attribute. Expects and string as parameter.
56              
57             =head2 parse
58              
59             Parses the C<load preferences> output stored in the C<raw_data> attribute, setting the C<data_parsed> attribute.
60              
61             The C<raw_data> attribute will be set to an reference to an empty array.
62              
63             =cut
64              
65             override 'parse' => sub {
66              
67             my $self = shift;
68             my $data_ref = $self->get_raw_data();
69             my %parsed_lines;
70              
71             foreach my $line ( @{$data_ref} ) {
72              
73             SWITCH: {
74              
75             if ( $line =~ LOAD_PREF_RESP ) {
76              
77             my @data = split( /\:\s/, $line );
78              
79             confess 'Caught invalid LOAD_PREF_RESP line' unless (@data);
80              
81             $self->set_location( pop(@data) );
82             $parsed_lines{answer} = $line;
83             last SWITCH;
84              
85             }
86              
87             if ( $line =~ LOAD_PREF_CMD ) {
88              
89             $parsed_lines{command} = $line;
90             last SWITCH;
91              
92             }
93              
94             if ( $line eq '' ) {
95              
96             last SWITCH;
97              
98             }
99             else {
100              
101             confess "Invalid data in line [$line]";
102              
103             }
104              
105             }
106              
107             }
108              
109             confess "Did not found any line with response\n"
110             unless ( defined( $self->get_location() ) );
111              
112             $self->set_data_parsed( \%parsed_lines );
113             $self->set_raw_data( [] );
114              
115             return 1;
116              
117             };
118              
119             =pod
120              
121             =head1 SEE ALSO
122              
123             =over 2
124              
125             =item *
126              
127             L<Siebel::Srvrmgr::ListParser::Output>
128              
129             =item *
130              
131             L<Moose>
132              
133             =back
134              
135             =head1 AUTHOR
136              
137             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
138              
139             =head1 COPYRIGHT AND LICENSE
140              
141             This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>.
142              
143             This file is part of Siebel Monitoring Tools.
144              
145             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
146             it under the terms of the GNU General Public License as published by
147             the Free Software Foundation, either version 3 of the License, or
148             (at your option) any later version.
149              
150             Siebel Monitoring Tools is distributed in the hope that it will be useful,
151             but WITHOUT ANY WARRANTY; without even the implied warranty of
152             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
153             GNU General Public License for more details.
154              
155             You should have received a copy of the GNU General Public License
156             along with Siebel Monitoring Tools. If not, see L<http://www.gnu.org/licenses/>.
157              
158             =cut
159              
160 7     7   60 no Moose;
  7         21  
  7         51  
161             __PACKAGE__->meta->make_immutable;