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