GX::HTTP::Body::Scalar

Module Version: 0.2000_01

NAME

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

SYNOPSIS

# 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 );

DESCRIPTION

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

METHODS

Constructor

new

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

$body = GX::HTTP::Body::Scalar->new( %attributes );
Attributes:
  • content ( string | SCALAR reference )

    A (reference to a) string of bytes.

  • readonly ( bool )

    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.

Returns:
Exceptions:

Alternative syntax:

$body = GX::HTTP::Body::Scalar->new( $content );
Arguments:
  • $content ( string | SCALAR reference )
Returns:
Exceptions:

Public Methods

add

Adds the given content to the message body.

$body->add( @content );
Arguments:
  • @content ( scalars )

    • byte strings
    • references to byte strings
    • references to subroutines returning byte strings
    • IO::Handle objects / GLOB references to read() bytes from
Exceptions:

as_string

Returns the message body as a byte string.

$string = $body->as_string;
Returns:
  • $string ( byte string )

clear

Clears the message body.

$body->clear;

Calling this method also resets the the readonly flag.

content

Returns a reference to the content string.

$content = $body->content;
Returns:
  • $content ( SCALAR reference )

length

Returns the size of the message body in bytes.

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

open

Returns an IO::File handle for the content string.

$handle = $body->open( $mode );
Arguments:
  • $mode ( string ) [ optional ]

    Supported modes: "<", ">" and ">>". Defaults to "<".

Returns:
Exceptions:

print

An alias for 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 );
Arguments:
  • $handle ( IO::File object | typeglob | GLOB reference )
Returns:
  • $result ( bool )

readonly

Returns / sets the readonly flag.

$bool = $body->readonly;
$bool = $body->readonly( $bool );
Arguments:
  • $bool ( bool ) [ optional ]
Returns:
  • $bool ( bool )

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.