Create New Item
Item Type
File
Folder
Item Name
Search file in folder and subfolders...
Are you sure want to rename?
File Manager
/
php
/
Filter
:
Stream.pm
Advanced Search
Upload
New Item
Settings
Back
Back Up
Advanced Editor
Save
# ================================================================== # Gossamer Threads Module Library - http://gossamer-threads.com/ # # GT::IPC::Filter::Stream # Author : Scott Beck # $Id: Stream.pm,v 1.4 2004/01/13 01:35:17 jagerman Exp $ # # Copyright (c) 2004 Gossamer Threads Inc. All Rights Reserved. # ================================================================== # # Description: Filter streams of input out to a streams ;). # package GT::IPC::Filter::Stream; # ================================================================== use strict; use base 'GT::Base'; sub new { # ---------------------------------------------------------------------------- my $class = shift; if (@_ == 1) { @_ = (output => $_[0]); } $class->fatal(BADARGS => "Arguments to new() must be a hash") if @_ & 1; my %opts = @_; my $output = delete $opts{output}; $class->fatal(BADARGS => "No output for new()") unless defined $output; $class->fatal(BADARGS => "No output passed to new() is not a code ref") unless ref($output) eq 'CODE'; return bless { output => $output }, $class; } sub put { # ---------------------------------------------------------------------------- my ($self, $in) = @_; $self->{output}->($$in); } sub flush { # ---------------------------------------------------------------------------- # Does nothing } 1; __END__ =head1 NAME GT::IPC::Filter::Block - Implements stream based filtering for output streams. =head1 SYNOPSIS use GT::IPC::Filter::Stream; my $filter = new GT::IPC::Filter::Block( sub { my $chunk = shift ... } ); # -or- my $filter = new GT::IPC::Filter::Block( output => sub { my $chunk = shift; .. }, ); $filter->put(\$data); $filter->flush; =head1 DESCRIPTION Implements stream based filtering to an output code reference. Used mainly in GT::IPC::Run, L<GT::IPC::Run> for details. Basically just a pass through to your code reference. =head1 METHODS There are three methods (as with all filters in this class). =head2 new Takes either a single argument, which is a code reference to call output with, or a hash of options. =over 4 =item output This is the code reference you would like called with each output. =head2 put This method takes a stream of data and passed it strait to your code reference. There is no buffering that happens here. =head2 flush This method does nothing. =head1 SEE ALSO See L<GT::IPC::Run>. =head1 MAINTAINER Scott Beck =head1 COPYRIGHT Copyright (c) 2004 Gossamer Threads Inc. All Rights Reserved. http://www.gossamer-threads.com/ =head1 VERSION Revision: $Id: Stream.pm,v 1.4 2004/01/13 01:35:17 jagerman Exp $ =cut