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