root/trunk/omnipitr/lib/OmniPITR/Program.pm

Revision 131, 1.7 kB (checked in by depesz, 4 years ago)

work in progress. backup still doesn't work, but i want to commit to prevent code loss

Line 
1 package OmniPITR::Program;
2 use strict;
3 use warnings;
4 use OmniPITR::Log;
5 use English qw( -no_match_vars );
6 use OmniPITR::Pidfile;
7 use Carp;
8
9 =head1 new()
10
11 Object contstructor.
12
13 Since all OmniPITR programs are based on object, and they start with
14 doing the same things (namely reading and validating command line
15 arguments) - this is wrapped in here, to avoid code duplication.
16
17 Constructor also handles pid file creation, in case it was requested.
18
19 =cut
20
21 sub new {
22     my $class = shift;
23     my $self = bless {}, $class;
24     $self->check_debug();
25     $self->read_args();
26     $self->validate_args();
27     $self->{ 'pid-file' } = OmniPITR::Pidfile->new( 'pidfile' => $self->{ 'pid-file' } ) if $self->{ 'pid-file' };
28
29     return $self;
30 }
31
32 =head1 check_debug()
33
34 Internal method providing --debug option handling to every omnipitr program.
35
36 If *first* argument to omnipitr program it will print to stderr all arguments, and environment variables.
37
38 =cut
39
40 sub check_debug {
41     my $self = shift;
42     return if 0 == scalar @ARGV;
43     return unless '--debug' eq $ARGV[ 0 ];
44
45     warn "DEBUG INFORMATION:\n";
46     for my $key ( sort keys %ENV ) {
47         warn sprintf( "ENV: '%s' => '%s'\n", $key, $ENV{ $key } );
48     }
49     warn "Command line arguments: [" . join( "] , [", @ARGV ) . "]\n";
50     shift @ARGV;
51
52     return;
53 }
54
55 =head1 run()
56
57 Just a stub method, that has to be overriden in subclasses.
58
59 =cut
60
61 sub run {
62     my $self = shift;
63     croak( "run() method in OmniPITR::Program was not overridden!" );
64 }
65
66 =head1 verbose()
67
68 Shortcut to make code a bit nicer.
69
70 Returns values of (command line given) verbose switch.
71
72 =cut
73
74 sub verbose { return shift->{ 'verbose' }; }
75
76 =head1 log()
77
78 Shortcut to make code a bit nicer.
79
80 Returns logger object.
81
82 =cut
83
84 sub log { return shift->{ 'log' }; }
85
86 1;
87
Note: See TracBrowser for help on using the browser.