From: Jarkko Hietaniemi Date: Sun, 27 May 2001 20:29:07 +0000 (+0000) Subject: Make Time::Piece::strptime() to be a function, not a method. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b59310eab4250075948eb8d24039fddf5fe4665d;p=p5sagit%2Fp5-mst-13.2.git Make Time::Piece::strptime() to be a function, not a method. p4raw-id: //depot/perl@10238 --- diff --git a/ext/Time/Piece/Piece.pm b/ext/Time/Piece/Piece.pm index 215f489..d948a8d 100644 --- a/ext/Time/Piece/Piece.pm +++ b/ext/Time/Piece/Piece.pm @@ -1,7 +1,7 @@ package Time::Piece; use strict; -use vars qw($VERSION @ISA @EXPORT %EXPORT_TAGS); +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); require Exporter; require DynaLoader; @@ -15,6 +15,10 @@ use Carp; gmtime ); +@EXPORT_OK = qw( + strptime +); + %EXPORT_TAGS = ( ':override' => 'internal', ); @@ -777,9 +781,8 @@ sub _ptime { } sub strptime { - my $time = shift; my $format = shift; - my $stime = @_ ? shift : "$time"; + my $stime = shift; my %ptime; while ($format ne '') { @@ -944,13 +947,17 @@ http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2000-01/msg00241.html =head1 USAGE -After importing this module, when you use localtime or gmtime in a scalar -context, rather than getting an ordinary scalar string representing the -date and time, you get a Time::Piece object, whose stringification happens -to produce the same effect as the localtime and gmtime functions. There is -also a new() constructor provided, which is the same as localtime(), except -when passed a Time::Piece object, in which case it's a copy constructor. The -following methods are available on the object: +After importing this module, when you use localtime(0 or gmtime() in +scalar context, rather than getting an ordinary scalar string +representing the date and time, you get a Time::Piece object, whose +stringification happens to produce the same effect as the localtime() +and gmtime(0 functions. + +There is also a new() constructor provided, which is the same as +localtime(), except when passed a Time::Piece object, in which case +it's a copy constructor. + +The following methods are available on the object: $t->s # 0..61 [1] # and 61: leap second and double leap second @@ -1024,7 +1031,7 @@ following methods are available on the object: Both wdayname (day) and monname (month) allow passing in a list to use to index the name of the days against. This can be useful if you need to implement some form of localisation without actually installing or -using locales. +using the locales provided by the operating system. my @days = qw( Dimanche Lundi Merdi Mercredi Jeudi Vendredi Samedi ); diff --git a/t/lib/time-piece.t b/t/lib/time-piece.t index bf41a7d..c62e36d 100644 --- a/t/lib/time-piece.t +++ b/t/lib/time-piece.t @@ -314,7 +314,9 @@ print "ok 84\n"; print "not " unless Time::Piece::_is_leap_year(1904); print "ok 85\n"; -my %T = $t->strptime("%T", "12:34:56"); +use Time::Piece 'strptime'; + +my %T = strptime("%T", "12:34:56"); print "not " unless keys %T == 3 && $T{H} == 12 && $T{M} == 34 && $T{S} == 56; print "ok 86\n";