
bailey at HMIVAX
Sep 26, 1995, 10:14 AM
Post #1 of 2
(79 views)
Permalink
|
|
Re: overloading standard subroutines?
|
|
>A simple question: can one overload one of Perl's "standard" subroutines? > >For example, in VMSperl (version 5.001, 950727D) the "gmtime" routine doesn't >work because the corresponding VAXCRTL routine doesn't work. But then >I write: > >sub gmtime { > local ($t) = @_; > $t = time() unless defined($t); > return (localtime($t - $ENV{'SYS$TIMEZONE_DIFFERENTIAL'})); >} > >This works fine (even gets the right answer!), as long as I name it >something *other* than gmtime. Calls to gmtime seem to use the built-in >(nonfunctional) routine. > >Getting gmtime working right would be nice, as a prerequisite for the >"timelocal" module if nothing else, but I'm interested in the more general >question of redefining or overloading the built-in functions as well. Is there >some OO-type syntax that I'm missing here? AFAIK, the answer is "not yet", really. There have been a few discussions on perl5-porters about allowing assignment to the typeglob *CORE::gmtime to redefine the builtin gmtime operator, but it's not working in any general sense yet. (I've copied this to p5p in case I've missed something; I'm sure the real experts will straighten me out.) For the moment, you have to define a C<sub gmtime { ... }> in each package, and turn all instances of C<gmtime> into C<&gmtime> or C<gmtime()>. WRT gmtime() specifically, we can problably cons up a replacement using VMS' native sys$utc routines. The newest DECCRTL has a working gmtime() as well, I believe, but we'll still have to put something together to support folks who're running older versions. Regards, Charles Bailey bailey [at] genetics
|