GX::HTTP::Body::Stream

Module Version: 0.2000_01

NAME

GX::HTTP::Body::Stream - Stream-based HTTP message body class

SYNOPSIS

# Load the class
use GX::HTTP::Body::Stream;

# Create a new filehandle-based body object
$body = GX::HTTP::Body::Stream->new( *FH );

# Create a new callback-based body object
$body = GX::HTTP::Body::Stream->new( \&code );

# Print the message body
$body->print_to( *STDOUT );

DESCRIPTION

This module provides the GX::HTTP::Body::Stream class which extends the GX::HTTP::Body class.

METHODS

Constructor

new

Returns a new GX::HTTP::Body::Stream object.

$body = GX::HTTP::Body::Stream->new( %attributes );
Attributes:
  • source ( object | typeglob | GLOB reference | CODE reference )

    The source of the content stream.

Returns:
Exceptions:

Alternative syntax:

$body = GX::HTTP::Body::Stream->new( $source );
Arguments:
  • $source ( object | typeglob | GLOB reference | CODE reference )
Returns:
Exceptions:

Public Methods

length

Returns "-1".

$length = $body->length;
Returns:
  • $length ( integer )

    Always "-1".

print_to

Prints the message body to the given filehandle, returning true on success or false on failure.

$result = $body->print_to( $handle );
Arguments:
  • $handle ( IO::File object | typeglob | GLOB reference )
Returns:
  • $result ( bool )

readonly

Returns true.

$bool = $body->readonly;
Returns:
  • $bool ( bool )

    Always true.

source

Returns the source of the content stream.

$source = $body->source;
Returns:
  • $source ( object | typeglob | GLOB reference | CODE reference )

EXAMPLES

Content Sources

Example #1

Simple callback example:

my $body = GX::HTTP::Body::Stream->new( sub {

my $outstream = shift;

for ( 1 .. 10 ) {
$outstream->print( $_ );
$outstream->flush;
sleep( 1 );
}

return;

} );

AUTHOR

Jörg A. Uzarek <uzarek@runlevelnull.de>

COPYRIGHT AND LICENSE

Copyright © 2009-2011 Jörg A. Uzarek.

This module is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License Version 3 as published by the Free Software Foundation.