1package Time::localtime; 2use strict; 3use 5.006_001; 4 5use Time::tm; 6 7our (@ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $VERSION); 8our ( 9 $tm_sec, $tm_min, $tm_hour, $tm_mday, 10 $tm_mon, $tm_year, $tm_wday, $tm_yday, 11 $tm_isdst 12); 13 14BEGIN { 15 use Exporter (); 16 @ISA = qw(Exporter Time::tm); 17 @EXPORT = qw(localtime ctime); 18 @EXPORT_OK = qw( 19 $tm_sec $tm_min $tm_hour $tm_mday 20 $tm_mon $tm_year $tm_wday $tm_yday 21 $tm_isdst 22 ); 23 %EXPORT_TAGS = ( FIELDS => [ @EXPORT_OK, @EXPORT ] ); 24 $VERSION = 1.03; 25} 26 27sub populate (@) { 28 return unless @_; 29 my $tmob = Time::tm->new(); 30 @$tmob = ( 31 $tm_sec, $tm_min, $tm_hour, $tm_mday, 32 $tm_mon, $tm_year, $tm_wday, $tm_yday, 33 $tm_isdst ) 34 = @_; 35 return $tmob; 36} 37 38sub localtime (;$) { populate CORE::localtime(@_ ? shift : time)} 39sub ctime (;$) { scalar CORE::localtime(@_ ? shift : time) } 40 411; 42 43__END__ 44 45=head1 NAME 46 47Time::localtime - by-name interface to Perl's built-in localtime() function 48 49=head1 SYNOPSIS 50 51 use Time::localtime; 52 printf "Year is %d\n", localtime->year() + 1900; 53 54 $now = ctime(); 55 56 use Time::localtime; 57 use File::stat; 58 $date_string = ctime(stat($file)->mtime); 59 60=head1 DESCRIPTION 61 62This module's default exports override the core localtime() function, 63replacing it with a version that returns "Time::tm" objects. 64This object has methods that return the similarly named structure field 65name from the C's tm structure from F<time.h>; namely sec, min, hour, 66mday, mon, year, wday, yday, and isdst. 67 68You may also import all the structure fields directly into your namespace 69as regular variables using the :FIELDS import tag. (Note that this still 70overrides your core functions.) Access these fields as 71variables named with a preceding C<tm_> in front their method names. 72Thus, C<$tm_obj-E<gt>mday()> corresponds to $tm_mday if you import 73the fields. 74 75The ctime() function provides a way of getting at the 76scalar sense of the original CORE::localtime() function. 77 78To access this functionality without the core overrides, 79pass the C<use> an empty import list, and then access 80function functions with their full qualified names. 81On the other hand, the built-ins are still available 82via the C<CORE::> pseudo-package. 83 84=head1 NOTE 85 86While this class is currently implemented using the Class::Struct 87module to build a struct-like class, you shouldn't rely upon this. 88 89=head1 AUTHOR 90 91Tom Christiansen 92