File Coverage

blib/lib/Time/Unix.pm
Criterion Covered Total %
statement 12 14 85.7
branch n/a
condition n/a
subroutine 4 6 66.6
pod 0 2 0.0
total 16 22 72.7


line stmt bran cond sub pod time code
1              
2             # $Id: Unix.pm,v 1.3 2001/09/19 18:32:29 nwiger Exp $
3             ####################################################################
4             #
5             # Copyright (c) 2000 Nathan Wiger
6             #
7             # This module simply exports a time() function which overrides the
8             # builtin time, forcing it to return the seconds since the UNIX
9             # epoch on all platforms. It also provides a systime() function for
10             # returning the local system's time.
11             #
12             ####################################################################
13             #
14             # This program is free software; you can redistribute it and/or
15             # modify it under the terms of the GNU General Public License
16             # as published by the Free Software Foundation; either version 2
17             # of the License, or (at your option) any later version.
18             #
19             # This program is distributed in the hope that it will be useful,
20             # but WITHOUT ANY WARRANTY; without even the implied warranty of
21             # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22             # GNU General Public License for more details.
23             #
24             # You should have received a copy of the GNU General Public License
25             # along with this program; if not, write to the Free Software
26             # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27             # 02111-1307, USA.
28             #
29             ####################################################################
30              
31             require 5.003;
32             package Time::Unix;
33              
34 1     1   246159 use Time::Local;
  1         2231  
  1         69  
35              
36 1     1   6 use strict;
  1         2  
  1         42  
37 1     1   5 use vars qw(@EXPORT @ISA $VERSION);
  1         6  
  1         106  
38             $VERSION = do { my @r=(q$Revision: 1.3 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r };
39              
40 1     1   5 use Exporter;
  1         1  
  1         150  
41             @ISA = qw(Exporter);
42             @EXPORT = qw(time systime);
43              
44             # Set up our time diff based on the difference in seconds
45             # between the UNIX epoch and the epoch on a given platform
46             my $DAY_SECS = 86400;
47             my $TIME_OFFSET = ($^O eq "MacOS")
48             ? (-24107 * $DAY_SECS) -
49             sprintf "%+0.4d", (timelocal(localtime) - timelocal(gmtime))
50             : 0;
51              
52 0     0 0   sub time () { CORE::time() + $TIME_OFFSET }
53              
54             # Dang typeglobs don't work right on CORE functions...
55 0     0 0   sub systime () { CORE::time() }
56              
57             1; # Hopefully Perl 6 will lose this...
58              
59             __END__