File Coverage

blib/lib/Siebel/Srvrmgr/Daemon/Action/ListComps.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr::Daemon::Action::ListComps;
2              
3             =pod
4              
5             =head1 NAME
6              
7             Siebel::Srvrmgr::Daemon::Action::ListComps - subclass of Siebel::Srvrmgr::Daemon::Action to deal with list comp output
8              
9             =head1 SYNOPSIS
10              
11             use Siebel::Srvrmgr::Daemon::Action::ListComps;
12              
13             my $action = Siebel::Srvrmgr::Daemon::Action::ListComps->new({ parser => Siebel::Srvrmgr::ListParser->new(),
14             params => [$myDumpFile]});
15              
16             $action->do(\@output);
17              
18             =cut
19              
20 5     5   9275 use Moose;
  5         11  
  5         50  
21 5     5   35735 use namespace::autoclean;
  5         13  
  5         54  
22              
23             extends 'Siebel::Srvrmgr::Daemon::Action';
24              
25             with 'Siebel::Srvrmgr::Daemon::Action::Serializable';
26              
27             =pod
28              
29             =head1 DESCRIPTION
30              
31             This subclass of L<Siebel::Srvrmgr::Daemon::Action> will try to find a L<Siebel::Srvrmgr::ListParser::Output::ListComp> object in the given array reference
32             given as parameter to the C<do> method and stores the parsed data from this object in a serialized file.
33              
34             =head1 METHODS
35              
36             =head2 do_parsed
37              
38             It will check if the object given as parameter is a L<Siebel::Srvrmgr::ListParser::Output::ListComp>. If true, it will call the C<get_servers> method
39             from this class and then iterate over the servers (objects from the class L<Siebel::Srvrmgr::ListParser::Output::ListComp::Server>)
40             calling their respective C<store> method to serialize themselves into the OS filesystem.
41              
42             The name of the filename used for data serialization will be the value of C<dump_file> append with the character '_' and the server name.
43              
44             This method will return 1 if this operation was executed sucessfuly, 0 otherwise.
45              
46             =cut
47              
48             override 'do_parsed' => sub {
49              
50             my $self = shift;
51             my $obj = shift;
52              
53             if ( $obj->isa( $self->get_exp_output() ) ) {
54              
55             my $servers_ref = $obj->get_servers();
56              
57             warn "Could not fetch servers\n"
58             unless ( scalar( @{$servers_ref} ) > 0 );
59              
60             foreach my $servername ( @{$servers_ref} ) {
61              
62             my $server = $obj->get_server($servername);
63              
64             if (
65             $server->isa(
66             'Siebel::Srvrmgr::ListParser::Output::ListComp::Server')
67             )
68             {
69              
70             my $filename =
71             $self->get_dump_file() . '_' . $server->get_name();
72              
73             $server->store($filename);
74             return 1;
75              
76             }
77             else {
78              
79             warn "could not fetch $servername data\n";
80              
81             }
82              
83             }
84              
85             }
86             else {
87              
88             return 0;
89              
90             }
91              
92             };
93              
94             override '_build_exp_output' => sub {
95              
96             return 'Siebel::Srvrmgr::ListParser::Output::Tabular::ListComp';
97              
98             };
99              
100             =pod
101              
102             =head1 SEE ALSO
103              
104             =over 4
105              
106             =item *
107              
108             L<Siebel::Srvrmgr::ListParser::Output::ListComp>
109              
110             =item *
111              
112             L<Siebel::Srvrmgr::ListParser::Output::ListComp::Server>
113              
114             =item *
115              
116             L<Siebel::Srvrmgr::Daemon::Action>
117              
118             =item *
119              
120             L<Siebel::Srvrmgr::Daemon::Action::Serializable>
121              
122             =back
123              
124             =head1 AUTHOR
125              
126             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.org<E<gt>
127              
128             =head1 COPYRIGHT AND LICENSE
129              
130             This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.org<E<gt>
131              
132             This file is part of Siebel Monitoring Tools.
133              
134             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
135             it under the terms of the GNU General Public License as published by
136             the Free Software Foundation, either version 3 of the License, or
137             (at your option) any later version.
138              
139             Siebel Monitoring Tools is distributed in the hope that it will be useful,
140             but WITHOUT ANY WARRANTY; without even the implied warranty of
141             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
142             GNU General Public License for more details.
143              
144             You should have received a copy of the GNU General Public License
145             along with Siebel Monitoring Tools. If not, see <http://www.gnu.org/licenses/>.
146              
147             =cut
148              
149             __PACKAGE__->meta->make_immutable;