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