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