GX::HTTP::Body::Scalar - Scalar-based HTTP message body class
# Load the class use GX::HTTP::Body::Scalar; # Create a new body object $body = GX::HTTP::Body::Scalar->new; # Add content $body->add( "Hello world!" ); # Get an IO::File handle to read from $handle = $body->open; # Get an IO::File handle to write to $handle = $body->open( '>' ); # Print the message body $body->print_to( *STDOUT );
This module provides the GX::HTTP::Body::Scalar class which extends the GX::HTTP::Body class.
new
Returns a new GX::HTTP::Body::Scalar object.
$body = GX::HTTP::Body::Scalar->new( %attributes );
content ( string | SCALAR reference )
content
SCALAR
A (reference to a) string of bytes.
readonly ( bool )
readonly
If set to true, a GX::Exception will be raised when an attempt is made to "add" content to the body or to "open" the body in-memory file in write or append mode. Useful for sending static content.
$body ( GX::HTTP::Body::Scalar object )
$body
GX::Exception
Alternative syntax:
$body = GX::HTTP::Body::Scalar->new( $content );
$content ( string | SCALAR reference )
$content
add
Adds the given content to the message body.
$body->add( @content );
@content ( scalars )
@content
byte strings
references to byte strings
references to subroutines returning byte strings
IO::Handle objects / GLOB references to read() bytes from
GLOB
read()
as_string
Returns the message body as a byte string.
$string = $body->as_string;
$string ( byte string )
$string
clear
Clears the message body.
$body->clear;
Calling this method also resets the the readonly flag.
Returns a reference to the content string.
$content = $body->content;
$content ( SCALAR reference )
length
Returns the size of the message body in bytes.
$length = $body->length;
$length ( integer )
$length
open
Returns an IO::File handle for the content string.
$handle = $body->open( $mode );
$mode ( string ) [ optional ]
$mode
Supported modes: "<", ">" and ">>". Defaults to "<".
$handle ( IO::File object )
$handle
print
An alias for add().
add()
$body->print( @content );
print_to
Prints the message body to the given filehandle, returning true on success or false on failure.
$result = $body->print_to( $handle );
$handle ( IO::File object | typeglob | GLOB reference )
$result ( bool )
$result
Returns / sets the readonly flag.
$bool = $body->readonly; $bool = $body->readonly( $bool );
$bool ( bool ) [ optional ]
$bool
$bool ( bool )
Jörg A. Uzarek <uzarek@runlevelnull.de>
Copyright (c) 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.
To install GX, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GX
CPAN shell
perl -MCPAN -e shell install GX
For more information on module installation, please visit the detailed CPAN module installation guide.