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