package Override;
# $Id: Override.PM,v 1.1 1997/08/08 18:06:45 AR Exp $

=begin preamble

\documentclass{article}
\usepackage{makeidx}
\usepackage{verbatim}
\usepackage{pdoc}
\usepackage{html}

\title{\texttt{Override.pm}}
\author{Axel Ramge}

\makeindex

\begin{document}

\maketitle
\tableofcontents

=cut

=begin latex

% $Id: Override.PM,v 1.1 1997/08/08 18:06:45 AR Exp $
In this package you should define functions which are not common to
all operating systems. The operating system can be identified with 
Perl's \verb|$^O| magic variable. Known values are: \verb|MacOS|, % '
\verb|MSWin32|, \verb|OS2| and thousends Unices.

You can override functions if this is needed for your OS.

=cut

use Exporter ();
@ISA = qw(Exporter);

=begin latex

The variable \verb|@EXPORT_OK| holds the name of exported functions. 
These functions have to be imported in the scripts explicitly, i.e.\
you have to write:
\begin{verbatim}
use Override qw(foo bar);

$foo = foo($bar);
\end{verbatim}

=cut

@EXPORT_OK = qw($DEBUG rename);

=begin latex

If you want to override builtin functions you can do this by simply
redefining them. But you \emph{must} leave the original function for
generic systems. For example, if you want to define the function \verb|tmpnam|
which is actually in the \verb|POSIX| package you can do this by 
redefining this function:
\begin{verbatim}
@EXPORT_OK = qw(... tmpnam);

sub tmpnam {
  if ($^O =~ /MSWin32/) {
    return ('C:\WINDOWS\TEMP\FOO'); # Don't really use this :-) '
  } else {
    POSIX::tmpnam();		# This is the generic case
  }
}
\end{verbatim}
and add it to \verb|@EXPORT_OK|. If you want to override a builtin function
you have to use \verb|CORE::foo()| to refer to the original builtin (Note:
It also works without the ``\verb|CORE::|'', but this is cleaner).

=cut

sub rename {
  if ($^O =~ /OS2/) {
    print STDERR "OS/2 rename: MV\n" if $DEBUG;
    return (! system("mv $_[0] $_[1]")); # returns negated exit of "move"
  } elsif ($^O =~ /MSWin32/) {
    print STDERR "Windoze rename: MOVE\n" if $DEBUG;
    return (! system("move $_[0] $_[1]"));
  } else {
    print STDERR "Generic rename\n" if $DEBUG;
    CORE::rename($_[0], $_[1]);
  }
}  

1;

=begin latex

\printindex

\end{document}

=cut
