IO::Cat - Object-oriented Perl implementation of cat(1)


IO-Cat documentation Contained in the IO-Cat distribution.

Index


Code Index:

NAME

Top

IO::Cat - Object-oriented Perl implementation of cat(1)

SYNOPSIS

Top

  require IO::Cat;

  my $meow = new IO::Cat '/etc/motd';
  $meow->cat( \*STDOUT, \*STDERR )
	or die "Can't cat /etc/motd: $!";

DESCRIPTION

Top

IO::Cat provides an intuitive, scalable, encapsulated interface to the common task of printing to a filehandle. Use it a few times, and you'll never know how you lived without it!

METHODS

Top

AUTHOR

Top

Dennis Taylor, <corbeau@execpc.com>

SEE ALSO

Top

cat(1) and the File::Cat module.


IO-Cat documentation Contained in the IO-Cat distribution.
package IO::Cat;

use strict;
use IO::File;
use Carp;
use vars qw($VERSION);

$VERSION = '1.01';



#'

sub new {
    my ($class, $file) = @_;
    my $self = {};

    bless $self, $class;
    $self->file( $file ) if defined $file;
    
    return $self;
}


sub file {
    my $self = shift;

    if (@_) {
        if ($self->{fh}) {
            $self->{fh}->close();
        }
        
        $self->{file} = $_[0];
        $self->{fh} = IO::File->new( $_[0] );
        unless ($self->{fh}) {
            croak "Can't open file $_[0]: $!";
        }
    }

    return $self->{fh};
}


sub cat ($) {
	my ($self, $output) = @_;
    my $input = $self->file();
    
	while (<$input>) {
		print $output $_;
	}
    $input->seek( 0, 0 );
	
	return( 1 );
}





sub cattail ($) {
	my ($self, $output) = @_;
    my $input = $self->file();
	my @lines = (0);

	while (<$input>) {
		$lines[$.] = $input->tell();
	}

	pop @lines;
	while (defined ($_ = pop @lines)) {
		$input->seek( $_, 0 );
		print $output scalar(<$input>);
	}
    $input->seek( 0, 0 );

	return (1);
}




1;