--- Available.pm 2003/10/05 22:26:54 1.6 +++ Available.pm 2003/10/06 09:40:52 1.7 @@ -3,6 +3,7 @@ use 5.001; use strict; use warnings; +use Carp; require Exporter; @@ -59,25 +60,25 @@ $self->{ARGS} = {@_}; $debug = $self->{ARGS}->{DEBUG}; - die("need start time") if (! $self->{ARGS}->{start}); + croak("need start time") if (! $self->{ARGS}->{start}); # calc start and stop seconds my ($hh,$mm,$ss) = split(/:/,$self->{ARGS}->{start},3); print STDERR "new: start time ",$hh||0,":",$mm||0,":",$ss||0,"\n" if ($debug); - my $s = $hh * 3600 || die("need at least hour specified for start time"); + my $s = $hh * 3600 || croak("need at least hour specified for start time"); $s += $mm * 60 if ($mm); $s += $ss if ($ss); $self->{start} = $s; - die("need end time") if (! $self->{ARGS}->{end}); + croak("need end time") if (! $self->{ARGS}->{end}); ($hh,$mm,$ss) = split(/:/,$self->{ARGS}->{end},3); print STDERR "new: end time ",$hh||0,":",$mm||0,":",$ss||0,"\n" if ($debug); - $s = $hh * 3600 || die("need at least hour specified for end time"); + $s = $hh * 3600 || croak("need at least hour specified for end time"); $s += $mm * 60 if ($mm); $self->{end} = $s; - die("need dayMask specified") if (! $self->{ARGS}->{dayMask}); + croak("need dayMask specified") if (! $self->{ARGS}->{dayMask}); $self->{dayMask} = $self->{ARGS}->{dayMask}; @@ -128,7 +129,7 @@ sub uptime { my $self = shift; - my $time = shift || die "need uptime timestamp to calculate uptime"; + my $time = shift || croak "need uptime timestamp to calculate uptime"; # calculate offset -- that is number of seconds since midnight my @lt = gmtime($time); @@ -182,7 +183,7 @@ sub downtime { my $self = shift; - my $time = shift || die "need downtime timestamp to calculate uptime"; + my $time = shift || croak "need downtime timestamp to calculate uptime"; # calculate offset -- that is number of seconds since midnight my @lt = gmtime($time); @@ -256,8 +257,8 @@ sub interval { my $self = shift; - my $from = shift || die "need start time for interval"; - my $to = shift || die "need end time for interval"; + my $from = shift || croak "need start time for interval"; + my $to = shift || croak "need end time for interval"; print STDERR "from:\t$from\t",scalar gmtime($from),"\n" if ($debug); print STDERR "to:\t$to\t",scalar gmtime($to),"\n" if ($debug); @@ -289,7 +290,7 @@ # add rest of last day print STDERR "t:\t$to\t",scalar gmtime($to),"\n" if ($debug); - $total -= $self->downtime($to); + $total = abs($total - $self->downtime($to)); print STDERR "total: $total (final)\n" if ($debug); return $total; @@ -302,7 +303,7 @@ sub day_in_interval { my $self = shift; - my $time = shift || die "need timestamp to check if day is in interval"; + my $time = shift || croak "need timestamp to check if day is in interval"; my @lt = gmtime($time); return $self->_dayOk($lt[6]); @@ -429,9 +430,6 @@ =over 8 =item * -Use croak and not die in module for better error handling - -=item * Allow arbitary (array?) of holidays to be included. =back