home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / IO / Tee.pm < prev   
Text File  |  1998-02-14  |  1KB  |  77 lines

  1. package IO::Tee;
  2.  
  3. =head1 NAME
  4.  
  5. IO::Handle - supply object methods for I/O handles
  6.  
  7. =head1 SYNOPSIS
  8.  
  9.     use IO::Tee;
  10.     
  11.     open(LOG, ">Logit");
  12.     
  13.     tie *EARL_GREY, q(IO::Tee), *STDOUT, *LOG;
  14.     
  15.     select(EARL_GREY);
  16.     
  17.     printf "%s\n", "Hello, World";
  18.  
  19. =head1 DESCRIPTION
  20.  
  21. C<IO::Tee> emulates a bit of the functionality of the UN*X F<tee> program. 
  22. Everything printed to an C<IO::Tee> file handle will be printed to all 
  23. file handles given as arguments to the tie. That's all, folks.
  24.  
  25. =head1 SEE ALSO
  26.  
  27. L<perltie>
  28.  
  29. =head1 AUTHOR
  30.  
  31. Matthias Neeracher E<lt>F<neeri@iis.ee.ethz.ch>E<gt>
  32.  
  33. =cut
  34.  
  35. BEGIN {
  36.     use strict;
  37.  
  38.     use Carp;
  39.     use Symbol;
  40. }
  41.  
  42. sub TIEHANDLE {
  43.     my @proxies = @_;
  44.     shift @proxies;
  45.     
  46.     bless \@proxies;
  47. }
  48.  
  49. sub PRINT
  50. {
  51.     croak 'Usage: print [FILEHANDLE|$filehandle] @items;'
  52.       if (@_ < 1);
  53.  
  54.     my($proxies) = shift;
  55.  
  56.     for my $handle (@$proxies) {
  57.         print $handle @_;
  58.     }
  59. }
  60.  
  61. sub PRINTF
  62. {
  63.     croak 'Usage: print [FILEHANDLE|$filehandle] $format, @items;'
  64.       if (@_ < 2);
  65.  
  66.     my($proxies) = shift;
  67.     my($format) = shift;
  68.     $format = sprintf($format, @_);
  69.  
  70.     for my $handle (@$proxies) {
  71.         print $handle $format;
  72.     }
  73. }
  74.  
  75. 1;
  76.  
  77.