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