| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #!/usr/local/bin/perl -w | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # | 
| 4 |  |  |  |  |  |  | # Copyright (C) 1995, 1996 Systemics Ltd (http://www.systemics.com/) | 
| 5 |  |  |  |  |  |  | # All rights reserved. | 
| 6 |  |  |  |  |  |  | # | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | package Stream::FileOutputStream; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | @FileOutputStream::ISA = qw(Stream::FileOutputStream); | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | # | 
| 13 |  |  |  |  |  |  | #	FileOutputStream | 
| 14 |  |  |  |  |  |  | # | 
| 15 |  |  |  |  |  |  | #		Inherits from OutputStream, redefining all of it's member | 
| 16 |  |  |  |  |  |  | #		functions: | 
| 17 |  |  |  |  |  |  | #			write | 
| 18 |  |  |  |  |  |  | # | 
| 19 |  |  |  |  |  |  | # | 
| 20 |  |  |  |  |  |  | #   Perhaps we should consider making this inherit from FileHandle? | 
| 21 |  |  |  |  |  |  | # | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 1 |  |  | 1 |  | 7 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 44 |  | 
| 25 | 1 |  |  | 1 |  | 6 | use Carp; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 80 |  | 
| 26 | 1 |  |  | 1 |  | 6 | use FileHandle; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 9 |  | 
| 27 | 1 |  |  | 1 |  | 417 | use POSIX; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 16 |  | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub usage | 
| 30 |  |  |  |  |  |  | { | 
| 31 | 0 |  |  | 0 | 0 | 0 | my ($package, $filename, $line, $subr) = caller(1); | 
| 32 | 0 |  |  |  |  | 0 | $Carp::CarpLevel = 2; | 
| 33 | 0 |  |  |  |  | 0 | croak "Usage: $subr(@_)"; | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | sub new | 
| 37 |  |  |  |  |  |  | { | 
| 38 | 2 | 50 |  | 2 | 0 | 167 | usage("FileHandle") unless @_ == 2; | 
| 39 |  |  |  |  |  |  |  | 
| 40 | 2 |  |  |  |  | 4 | my $type = shift; my $self = {}; bless $self, $type; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 4 |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 2 |  |  |  |  | 4 | my $arg = shift; | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 2 | 50 | 33 |  |  | 16 | if (defined ref($arg) && ref($arg) eq 'FileHandle') | 
| 45 |  |  |  |  |  |  | { | 
| 46 | 0 |  |  |  |  | 0 | $self->{'fh'} = $arg; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  | else | 
| 49 |  |  |  |  |  |  | { | 
| 50 | 2 |  |  |  |  | 16 | $self->{'fh'} = new FileHandle $arg, 'w'; | 
| 51 | 2 | 50 |  |  |  | 360 | (defined($self->{'fh'})) || return "Could not open $arg"; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 2 |  |  |  |  | 13 | $self; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub close | 
| 58 |  |  |  |  |  |  | { | 
| 59 | 1 |  |  | 1 | 0 | 17 | shift->{'fh'}->close(); | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  |  | 
| 62 |  |  |  |  |  |  | sub write | 
| 63 |  |  |  |  |  |  | { | 
| 64 | 24 | 50 |  | 24 | 0 | 47 | usage("data") unless @_ == 2; | 
| 65 |  |  |  |  |  |  |  | 
| 66 | 24 |  |  |  |  | 25 | my $self = shift; | 
| 67 | 24 |  |  |  |  | 24 | my $data = shift; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 24 |  |  |  |  | 65 | $self->{'fh'}->print($data); | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | 1; |