File Coverage

blib/lib/Siebel/Srvrmgr.pm
Criterion Covered Total %
statement 27 28 96.4
branch 6 10 60.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 2 2 100.0
total 42 49 85.7


line stmt bran cond sub pod time code
1             package Siebel::Srvrmgr;
2 22     22   4593 use warnings;
  22         33  
  22         761  
3 22     22   90 use strict;
  22         22  
  22         660  
4 22     22   16502 use Log::Log4perl;
  22         728857  
  22         124  
5 22     22   1165 use Carp;
  22         29  
  22         5221  
6              
7             our $VERSION = '0.16';
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 13311     13311 1 10881 my $cfg = undef;
49              
50 13311         24063 local $/;
51              
52 13311 100       20270 if ( $ENV{SIEBEL_SRVRMGR_DEBUG} ) {
53              
54 2266 50 33     49950 if ( ( -e $ENV{SIEBEL_SRVRMGR_DEBUG} )
55             and ( -f $ENV{SIEBEL_SRVRMGR_DEBUG} ) )
56             {
57              
58 2266 50       49397 open( my $in, '<', $ENV{SIEBEL_SRVRMGR_DEBUG} )
59             or confess "Cannot read $ENV{SIEBEL_SRVRMGR_DEBUG}: $!";
60 2266         20692 $cfg = <$in>;
61 2266         15967 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 11045         90796 $cfg = <Siebel::Srvrmgr::DATA>;
75              
76             }
77              
78 13311         33984 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             =cut
89              
90             sub gimme_logger {
91              
92 116     116 1 1381 my $class = shift;
93 116         161 my $package = shift;
94              
95 116 50       306 confess 'package parameter must be defined' unless ( defined($package) );
96 116         421 my $cfg = Siebel::Srvrmgr->logging_cfg();
97              
98 116 50       954 confess "Could not start logging facilities"
99             unless ( Log::Log4perl->init_once( \$cfg ) );
100              
101 116         18272 return Log::Log4perl->get_logger($package);
102              
103             }
104              
105             =pod
106              
107             =head1 SEE ALSO
108              
109             The classes below might give you a introduction of the available classes and features:
110              
111             =over
112              
113             =item *
114              
115             L<Siebel::Srvrmgr::Daemon>
116              
117             =item *
118              
119             L<Siebel::Srvrmgr::ListParser>
120              
121             =item *
122              
123             The project web page at L<http://code.google.com/p/siebel-monitoring-tools/> contains more information about project features and state.
124              
125             =back
126              
127             =head1 AUTHOR
128              
129             Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>
130              
131             =head1 COPYRIGHT AND LICENSE
132              
133             This software is copyright (c) 2012 of Alceu Rodrigues de Freitas Junior, E<lt>arfreitas@cpan.orgE<gt>
134              
135             This file is part of Siebel Monitoring Tools.
136              
137             Siebel Monitoring Tools is free software: you can redistribute it and/or modify
138             it under the terms of the GNU General Public License as published by
139             the Free Software Foundation, either version 3 of the License, or
140             (at your option) any later version.
141              
142             Siebel Monitoring Tools is distributed in the hope that it will be useful,
143             but WITHOUT ANY WARRANTY; without even the implied warranty of
144             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
145             GNU General Public License for more details.
146              
147             You should have received a copy of the GNU General Public License
148             along with Siebel Monitoring Tools. If not, see <http://www.gnu.org/licenses/>.
149              
150             =cut
151              
152             1;
153              
154             __DATA__
155             log4perl.appender.A1=Log::Log4perl::Appender::Screen
156             log4perl.appender.A1.stderr=0
157             log4perl.appender.A1.layout=Log::Log4perl::Layout::PatternLayout
158             log4perl.appender.A1.layout.ConversionPattern=%d %p> %F{1}:%L %M - %m%n
159             log4perl.logger.Siebel.Srvrmgr.Daemon=FATAL, A1
160             log4perl.logger.Siebel.Srvrmgr.ListParser=FATAL, A1