home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _01047b1214f3c9c9d598fef0da291adf < prev    next >
Encoding:
Text File  |  2004-06-01  |  828 b   |  47 lines

  1. package PPM::Trace;
  2.  
  3. use strict;
  4. use Exporter;
  5.  
  6. our $VERSION = '3.00';
  7. our @EXPORT_OK = qw(trace);
  8. our @ISA = qw(Exporter);
  9.  
  10. my $trace_fh;        # the filehandle
  11. my $trace_level = 0;
  12.  
  13. sub trace_init {
  14.     my $file = shift;
  15.     $trace_level = shift;
  16.     open ($trace_fh, '>>', $file) or die "Can't append $file: $!";
  17.     select((select($trace_fh), $| = 1)[0]);
  18.     my $t = localtime;
  19.     trace($trace_level, <<END);
  20. $0: trace started $t.
  21. END
  22. }
  23.  
  24. sub trace_fini {
  25.     close ($trace_fh) or die "Can't close trace file: $!"
  26.       if $trace_fh;
  27. }
  28.  
  29. sub trace_level {
  30.     $trace_level = $_[0] if defined $_[0];
  31.     $trace_level;
  32. }
  33.  
  34. sub trace {
  35.     my $lvl = shift;
  36.     if ($trace_level and $trace_fh and $trace_level >= $lvl) {
  37.     print $trace_fh @_;
  38.     }
  39.     1;
  40. }
  41.  
  42. END {
  43.     trace_fini();
  44. }
  45.  
  46. 1;
  47.