home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl560.zip / lib / Time / localtime.pm < prev    next >
Text File  |  2000-01-22  |  2KB  |  86 lines

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