File Coverage

blib/lib/Siebel/Srvrmgr.pm
Criterion Covered Total %
statement 28 29 96.5
branch 9 12 75.0
condition 3 6 50.0
subroutine 6 6 100.0
pod 2 2 100.0
total 48 55 87.2


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr;
2 22     22   81972 use warnings;
  22         1106  
  22         3051  
3 22     22   121 use strict;
  22         1063  
  22         535  
4 22     22   27537 use Log::Log4perl;
  22         1141065  
  22         131  
5 22     22   1446 use Carp;
  22         52  
  22         25443  
6              
7             our $VERSION = "0.20";
8              
9             =pod
10              
11             =head1 NAME
12              
13             Siebel::Srvrmgr - utilities to be used with the Siebel srvrmgr program
14              
15             =head1 DESCRIPTION
16              
17             The distribution Siebel-Srvrmgr was created to define a set of tools to interact with the C<srvrmgr> program from Siebel.
18              
19             It was started initially to create a parser for the project Siebel Monitoring Tools (L<http://code.google.com/p/siebel-monitoring-tools/>) and later was grown to a
20             set of more generic functionality, thus making sense to be published at CPAN.
21              
22             This package used to be only Pod, but since release 0.09 it has a logging feature. See logging_cfg for details.
23              
24             B<Since release 0.15, this distribution breaks API compabitility with previous releases. Consider yourself warned.>
25              
26             =head1 CLASS METHODS
27              
28             =head2 logging_cfg
29              
30             Returns a string with the configuration to be used by a L<Log::Log4perl> instance.
31              
32             The configuration of L<Log::Log4perl> is available after the C<__DATA__> code block of this package. Logging is disabled by default, but it can be enabled by
33             only commenting the line:
34              
35             log4perl.threshold = OFF
36              
37             with the default "#" Perl comment character.
38              
39             Logging is quite flexible (see L<Log::Log4perl> for details) but the default configuration uses only FATAL level printing messages to STDOUT.
40              
41             It is also possible to set a different L<Log::Log4perl> configuration file by setting the environment variable SIEBEL_SRVRMGR_DEBUG with the complete location to the
42             configuration file. This module will look first for this variable configuration and if found, will try to use the configuration from there.
43              
44             =cut
45              
46             sub logging_cfg {
47              
48 17     17 1 38 my $cfg = undef;
49              
50 17         83 local $/;
51              
52 17 100       80 if ( $ENV{SIEBEL_SRVRMGR_DEBUG} ) {
53              
54 2 50 33     177 if ( ( -e $ENV{SIEBEL_SRVRMGR_DEBUG} )
55             and ( -f $ENV{SIEBEL_SRVRMGR_DEBUG} ) )
56             {
57              
58             open( my $in, '<', $ENV{SIEBEL_SRVRMGR_DEBUG} )
59 2 50       123 or confess "Cannot read $ENV{SIEBEL_SRVRMGR_DEBUG}: $!";
60 2         59 $cfg = <$in>;
61 2         99 close($in);
62              
63             }
64             else {
65              
66 0         0 confess
67             "SIEBEL_SRVRMGR_DEBUG is defined ($ENV{SIEBEL_SRVRMGR_DEBUG}) but the value does not exists in the filesystem or is not a file";
68              
69             }
70              
71             }
72             else {
73              
74 15         349 $cfg = <Siebel::Srvrmgr::DATA>;
75              
76             }
77              
78 17         161 return $cfg;
79              
80             }
81              
82             =pod
83              
84             =head2 gimme_logger
85              
86             This method returns a L<Log::Log4perl::Logger> object as defined by the C<logging_cfg> method.
87              
88             It expects as parameters the following items:
89              
90             =over
91              
92             =item *
93              
94             package: string with the name of the package that wants a logger. This is a required parameter.
95              
96             =back
97              
98             The configuration will B<not> be read again after initialization.
99              
100             =cut
101              
102             sub gimme_logger {
103              
104 14686     14686 1 28082 my $class = shift;
105 14686         19754 my $package = shift;
106              
107 14686 100       41064 if ( Log::Log4perl->initialized() ) {
108              
109 14667         79841 return Log::Log4perl->get_logger($package);
110              
111             }
112              
113 19 100 66     430 confess 'package parameter must be defined'
114             unless ( ( defined($package) ) and ( $package =~ /^[\w\:]+$/ ) );
115              
116 17 50       101 confess "Could not start logging facilities"
117             unless ( Log::Log4perl->init_once( \$class->logging_cfg() ) );
118              
119 17         98267 return Log::Log4perl->get_logger($package);
120              
121             }
122              
123             =pod
124              
125             =head1 SEE ALSO
126              
127             The classes below might give you a introduction of the available classes and features:
128              
129             =over
130              
131             =item *
132              
133             L<Siebel::Srvrmgr::Daemon>
134              
135             =item *
136              
137             L<Siebel::Srvrmgr::ListParser>
138              
139             =item *
140              
141             The project web page at L<https://github.com/glasswalk3r/siebel-monitoring-tools/> contains more information about project features and state.
142              
143             =back
144              
145             =head1 AUTHOR
146              
147             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>
148              
149             =head1 COPYRIGHT AND LICENSE
150              
151             This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>
152              
153             This file is part of Siebel Monitoring Tools.
154              
155             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
156             it under the terms of the GNU General Public License as published by
157             the Free Software Foundation, either version 3 of the License, or
158             (at your option) any later version.
159              
160             Siebel Monitoring Tools is distributed in the hope that it will be useful,
161             but WITHOUT ANY WARRANTY; without even the implied warranty of
162             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
163             GNU General Public License for more details.
164              
165             You should have received a copy of the GNU General Public License
166             along with Siebel Monitoring Tools. If not, see <http://www.gnu.org/licenses/>.
167              
168             =cut
169              
170             1;
171              
172             __DATA__
173             log4perl.appender.A1=Log::Log4perl::Appender::Screen
174             log4perl.appender.A1.stderr=0
175             log4perl.appender.A1.layout=Log::Log4perl::Layout::PatternLayout
176             log4perl.appender.A1.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%n
177             log4perl.logger.Siebel.Srvrmgr.Daemon=FATAL, A1
178             log4perl.logger.Siebel.Srvrmgr.ListParser=FATAL, A1