GX::HTTP::Body::File - File-based HTTP message body class
# Load the class use GX::HTTP::Body::File; # Create a new body object $body = GX::HTTP::Body::File->new( '/tmp/body.content' ); # 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::File class which extends the GX::HTTP::Body class.
new
Returns a new GX::HTTP::Body::File object.
$body = GX::HTTP::Body::File->new( %attributes );
cleanup ( bool )
cleanup
A boolean flag indicating whether or not to delete the associated file when the body object is cleared or destroyed. False by default, but automatically set to true (unless specified otherwise) when a temporary body file is created. Ignored if the readonly flag is set to true.
readonly
file ( string )
file
A path to the file that is used to store the message body. If omitted, a temporary file will be used instead.
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 file in write or append mode. Useful for preventing accidental modifications when sending static files.
$body ( GX::HTTP::Body::File object )
$body
GX::Exception
Alternative syntax:
$body = GX::HTTP::Body::File->new( $file );
$file ( string ) [ optional ]
$file
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 | undef )
$string
undef
Returns / sets the cleanup flag.
$bool = $body->cleanup; $bool = $body->cleanup( $bool );
$bool ( bool ) [ optional ]
$bool
$bool ( bool )
Unless set explicitly, the cleanup flag is automatically set to true when a temporary body file is created.
clear
Clears the message body.
$body->clear;
Calling this method resets the cleanup flag, the readonly flag and the file attribute. Additionally, the associated file is deleted if the cleanup flag had been set to true and the file was not marked as read-only.
Returns / sets the path to the associated file.
$file = $body->file; $file = $body->file( $file );
$file ( string )
length
Returns the size of the message body in bytes.
$length = $body->length;
$length ( integer )
$length
open
Returns an opened IO::File handle for the associated file.
$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 specified 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 );
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.