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              
3 22     22   138103 use warnings;
  22         60  
  22         931  
4 22     22   143 use strict;
  22         53  
  22         694  
5 22     22   13016 use Log::Log4perl 1.41;
  22         921187  
  22         150  
6 22     22   1863 use Carp;
  22         58  
  22         8932  
7             our $VERSION = '0.29'; #VERSION
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 19     19 1 57 my $cfg = undef;
49              
50 19         118 local $/;
51              
52 19 100       127 if ( $ENV{SIEBEL_SRVRMGR_DEBUG} ) {
53              
54 3 50 33     123 if ( ( -e $ENV{SIEBEL_SRVRMGR_DEBUG} )
55             and ( -f $ENV{SIEBEL_SRVRMGR_DEBUG} ) )
56             {
57              
58             open( my $in, '<', $ENV{SIEBEL_SRVRMGR_DEBUG} )
59 3 50       166 or confess "Cannot read $ENV{SIEBEL_SRVRMGR_DEBUG}: $!";
60 3         70 $cfg = <$in>;
61 3         36 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 16         776 $cfg = <Siebel::Srvrmgr::DATA>;
75              
76             }
77              
78 19         212 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 52478     52478 1 117133 my $class = shift;
105 52478         88289 my $package = shift;
106              
107 52478 100       147026 if ( Log::Log4perl->initialized() ) {
108              
109 52457         272418 return Log::Log4perl->get_logger($package);
110              
111             }
112              
113 21 100 66     397 confess 'package parameter must be defined'
114             unless ( ( defined($package) ) and ( $package =~ /^[\w\:]+$/ ) );
115              
116 19 50       237 confess "Could not start logging facilities"
117             unless ( Log::Log4perl->init_once( \$class->logging_cfg() ) );
118              
119 19         129012 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             =item *
144              
145             PPM package: if you are a Active Perl user, you might be happy to know that there are PPM packages created automatically from this distribution
146             at L<https://code.activestate.com/ppm/Siebel-Srvrmgr/>.
147              
148             =back
149              
150             =head1 AUTHOR
151              
152             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>
153              
154             =head1 COPYRIGHT AND LICENSE
155              
156             This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>
157              
158             This file is part of Siebel Monitoring Tools.
159              
160             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
161             it under the terms of the GNU General Public License as published by
162             the Free Software Foundation, either version 3 of the License, or
163             (at your option) any later version.
164              
165             Siebel Monitoring Tools is distributed in the hope that it will be useful,
166             but WITHOUT ANY WARRANTY; without even the implied warranty of
167             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
168             GNU General Public License for more details.
169              
170             You should have received a copy of the GNU General Public License
171             along with Siebel Monitoring Tools. If not, see <http://www.gnu.org/licenses/>.
172              
173             =cut
174              
175             1;
176              
177             __DATA__
178             log4perl.appender.A1=Log::Log4perl::Appender::Screen
179             log4perl.appender.A1.stderr=0
180             log4perl.appender.A1.layout=Log::Log4perl::Layout::PatternLayout
181             log4perl.appender.A1.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%n
182             log4perl.logger.Siebel.Srvrmgr.Daemon=FATAL, A1
183             log4perl.logger.Siebel.Srvrmgr.ListParser=FATAL, A1