1*0Sstevel@tonic-gatepackage Time::gmtime; 2*0Sstevel@tonic-gateuse strict; 3*0Sstevel@tonic-gateuse 5.006_001; 4*0Sstevel@tonic-gate 5*0Sstevel@tonic-gateuse Time::tm; 6*0Sstevel@tonic-gate 7*0Sstevel@tonic-gateour(@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION); 8*0Sstevel@tonic-gateBEGIN { 9*0Sstevel@tonic-gate use Exporter (); 10*0Sstevel@tonic-gate @ISA = qw(Exporter Time::tm); 11*0Sstevel@tonic-gate @EXPORT = qw(gmtime gmctime); 12*0Sstevel@tonic-gate @EXPORT_OK = qw( 13*0Sstevel@tonic-gate $tm_sec $tm_min $tm_hour $tm_mday 14*0Sstevel@tonic-gate $tm_mon $tm_year $tm_wday $tm_yday 15*0Sstevel@tonic-gate $tm_isdst 16*0Sstevel@tonic-gate ); 17*0Sstevel@tonic-gate %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] ); 18*0Sstevel@tonic-gate $VERSION = 1.02; 19*0Sstevel@tonic-gate} 20*0Sstevel@tonic-gateuse vars @EXPORT_OK; 21*0Sstevel@tonic-gate 22*0Sstevel@tonic-gatesub populate (@) { 23*0Sstevel@tonic-gate return unless @_; 24*0Sstevel@tonic-gate my $tmob = Time::tm->new(); 25*0Sstevel@tonic-gate @$tmob = ( 26*0Sstevel@tonic-gate $tm_sec, $tm_min, $tm_hour, $tm_mday, 27*0Sstevel@tonic-gate $tm_mon, $tm_year, $tm_wday, $tm_yday, 28*0Sstevel@tonic-gate $tm_isdst ) 29*0Sstevel@tonic-gate = @_; 30*0Sstevel@tonic-gate return $tmob; 31*0Sstevel@tonic-gate} 32*0Sstevel@tonic-gate 33*0Sstevel@tonic-gatesub gmtime (;$) { populate CORE::gmtime(@_ ? shift : time)} 34*0Sstevel@tonic-gatesub gmctime (;$) { scalar CORE::gmtime(@_ ? shift : time)} 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate1; 37*0Sstevel@tonic-gate__END__ 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate=head1 NAME 40*0Sstevel@tonic-gate 41*0Sstevel@tonic-gateTime::gmtime - by-name interface to Perl's built-in gmtime() function 42*0Sstevel@tonic-gate 43*0Sstevel@tonic-gate=head1 SYNOPSIS 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate use Time::gmtime; 46*0Sstevel@tonic-gate $gm = gmtime(); 47*0Sstevel@tonic-gate printf "The day in Greenwich is %s\n", 48*0Sstevel@tonic-gate (qw(Sun Mon Tue Wed Thu Fri Sat Sun))[ gm->wday() ]; 49*0Sstevel@tonic-gate 50*0Sstevel@tonic-gate use Time::gmtime w(:FIELDS; 51*0Sstevel@tonic-gate printf "The day in Greenwich is %s\n", 52*0Sstevel@tonic-gate (qw(Sun Mon Tue Wed Thu Fri Sat Sun))[ gm_wday() ]; 53*0Sstevel@tonic-gate 54*0Sstevel@tonic-gate $now = gmctime(); 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate use Time::gmtime; 57*0Sstevel@tonic-gate use File::stat; 58*0Sstevel@tonic-gate $date_string = gmctime(stat($file)->mtime); 59*0Sstevel@tonic-gate 60*0Sstevel@tonic-gate=head1 DESCRIPTION 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gateThis module's default exports override the core gmtime() function, 63*0Sstevel@tonic-gatereplacing it with a version that returns "Time::tm" objects. 64*0Sstevel@tonic-gateThis object has methods that return the similarly named structure field 65*0Sstevel@tonic-gatename from the C's tm structure from F<time.h>; namely sec, min, hour, 66*0Sstevel@tonic-gatemday, mon, year, wday, yday, and isdst. 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gateYou may also import all the structure fields directly into your namespace 69*0Sstevel@tonic-gateas regular variables using the :FIELDS import tag. (Note that this 70*0Sstevel@tonic-gatestill overrides your core functions.) Access these fields as variables 71*0Sstevel@tonic-gatenamed with a preceding C<tm_> in front their method names. Thus, 72*0Sstevel@tonic-gateC<$tm_obj-E<gt>mday()> corresponds to $tm_mday if you import the fields. 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gateThe gmctime() function provides a way of getting at the 75*0Sstevel@tonic-gatescalar sense of the original CORE::gmtime() function. 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gateTo access this functionality without the core overrides, 78*0Sstevel@tonic-gatepass the C<use> an empty import list, and then access 79*0Sstevel@tonic-gatefunction functions with their full qualified names. 80*0Sstevel@tonic-gateOn the other hand, the built-ins are still available 81*0Sstevel@tonic-gatevia the C<CORE::> pseudo-package. 82*0Sstevel@tonic-gate 83*0Sstevel@tonic-gate=head1 NOTE 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gateWhile this class is currently implemented using the Class::Struct 86*0Sstevel@tonic-gatemodule to build a struct-like class, you shouldn't rely upon this. 87*0Sstevel@tonic-gate 88*0Sstevel@tonic-gate=head1 AUTHOR 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gateTom Christiansen 91