File Coverage

blib/lib/Apache/Voodoo/Install/Pid.pm
Criterion Covered Total %
statement 9 31 29.0
branch 0 10 0.0
condition 0 3 0.0
subroutine 3 6 50.0
pod 0 2 0.0
total 12 52 23.0


line stmt bran cond sub pod time code
1             ###############################################################################
2             #
3             # Apache::Voodoo::Install::Pid - Pid file handler
4             #
5             # This object is used by Voodoo internally.
6             #
7             ###############################################################################
8             package Apache::Voodoo::Install::Pid;
9              
10             $VERSION = "3.0200";
11              
12 1     1   3746 use base("Apache::Voodoo::Install");
  1         2  
  1         244  
13              
14 1     1   12 use strict;
  1         3  
  1         46  
15 1     1   1153 use File::Pid;
  1         8419  
  1         14  
16              
17             sub new {
18 0     0 0   my $class = shift;
19 0           my %params = @_;
20              
21 0           my $self = {};
22              
23 0           bless($self,$class);
24              
25 0 0 0       if (!$params{'pretend'} && $<) {
26 0           print "\nSorry, only root can do this.\n\n";
27 0           exit;
28             }
29              
30 0 0         if ($self->{'pretend'}) {
31 0           $self->mesg("== Pretending to run ==");
32             }
33              
34 0           $self->{'pid'} = File::Pid->new({file => '/tmp/voodoo-install.pid'});
35 0           my $id = $self->{'pid'}->running;
36 0 0         if ($id) {
37 0           print "ERROR: Already Running ($id)\n";
38 0           exit;
39             }
40              
41 0 0         unless ($self->{'pid'}->write) {
42 0           die "ERROR: Couldn't write pid: $!";
43             }
44              
45 0           return $self;
46             }
47              
48             sub remove {
49 0     0 0   my $self = shift;
50              
51             # prevent double call of File::Pid::remove in cases
52             # where A::V::I::Pid was called directly
53 0 0         if (defined($self->{'pid'})) {
54 0           $self->{'pid'}->remove;
55 0           $self->{'pid'} = undef;
56             }
57             }
58              
59             sub DESTROY {
60 0     0     $_[0]->remove;
61             }
62              
63             1;
64              
65             ################################################################################
66             # Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org).
67             # All rights reserved.
68             #
69             # You may use and distribute Apache::Voodoo under the terms described in the
70             # LICENSE file include in this package. The summary is it's a legalese version
71             # of the Artistic License :)
72             #
73             ################################################################################