Minimal pod, and removed req on YAML - tests will skip all if not found
Ash Berlin [Fri, 23 Mar 2007 15:03:19 +0000 (15:03 +0000)]
Changes
MANIFEST [deleted file]
META.yml [deleted file]
Makefile.PL
lib/HTTP/Body.pm
lib/HTTP/Body/Compat.pm
lib/HTTP/Body/Context.pm
lib/HTTP/Body/Parser.pm
t/04multipart.t
t/05urlencoded.t
t/06octetstream.t

diff --git a/Changes b/Changes
index 50c97f5..43b9df7 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 This file documents the revision history for Perl extension HTTP::Body.
 
+        - 0 length files dont silent disapear, Ash Berlin http://rt.cpan.org/NoAuth/Bug.html?id=25392
+        - YAML is no longer a prereq, tests just wont do anything without it or YAML::Syck
+
 0.6   2006-01-06 00:00:00
         - Fixed buffer bug in OctetStream, reported by Daisuke Murase <typester@cpan.org>.
         - Fixed YAML prereq, reported by Jess Robinson
diff --git a/MANIFEST b/MANIFEST
deleted file mode 100644 (file)
index 61391c3..0000000
--- a/MANIFEST
+++ /dev/null
@@ -1,57 +0,0 @@
-Changes
-lib/HTTP/Body.pm
-lib/HTTP/Body/MultiPart.pm
-lib/HTTP/Body/OctetStream.pm
-lib/HTTP/Body/UrlEncoded.pm
-Makefile.PL
-MANIFEST                       This list of files
-META.yml
-README
-t/01use.t
-t/02pod.t
-t/03podcoverage.t
-t/04multipart.t
-t/05urlencoded.t
-t/06octetstream.t
-t/data/multipart/001-content.dat
-t/data/multipart/001-headers.yml
-t/data/multipart/001-results.yml
-t/data/multipart/002-content.dat
-t/data/multipart/002-headers.yml
-t/data/multipart/002-results.yml
-t/data/multipart/003-content.dat
-t/data/multipart/003-headers.yml
-t/data/multipart/003-results.yml
-t/data/multipart/004-content.dat
-t/data/multipart/004-headers.yml
-t/data/multipart/004-results.yml
-t/data/multipart/005-content.dat
-t/data/multipart/005-headers.yml
-t/data/multipart/005-results.yml
-t/data/multipart/006-content.dat
-t/data/multipart/006-headers.yml
-t/data/multipart/006-results.yml
-t/data/multipart/007-content.dat
-t/data/multipart/007-headers.yml
-t/data/multipart/007-results.yml
-t/data/multipart/008-content.dat
-t/data/multipart/008-headers.yml
-t/data/multipart/008-results.yml
-t/data/multipart/009-content.dat
-t/data/multipart/009-headers.yml
-t/data/multipart/009-results.yml
-t/data/multipart/010-content.dat
-t/data/multipart/010-headers.yml
-t/data/multipart/010-results.yml
-t/data/multipart/011-content.dat
-t/data/multipart/011-headers.yml
-t/data/multipart/011-results.yml
-t/data/octetstream/001-content.dat
-t/data/octetstream/001-headers.yml
-t/data/octetstream/001-results.dat
-t/data/octetstream/002-content.dat
-t/data/octetstream/002-headers.yml
-t/data/octetstream/002-results.dat
-t/data/urlencoded/001-content.dat
-t/data/urlencoded/001-headers.yml
-t/data/urlencoded/001-results.yml
diff --git a/META.yml b/META.yml
deleted file mode 100644 (file)
index 66e2078..0000000
--- a/META.yml
+++ /dev/null
@@ -1,14 +0,0 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
-name:         HTTP-Body
-version:      0.4
-version_from: lib/HTTP/Body.pm
-installdirs:  site
-requires:
-    Carp:                          0
-    File::Temp:                    0.14
-    IO::File:                      0
-    YAML:                          0
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.17
index 57db0f0..4cf76bb 100644 (file)
@@ -15,6 +15,5 @@ WriteMakefile(
         IO::File         => 0,
         Params::Validate => 0,
         Scalar::Util     => 0,
-        YAML             => '0.39'
     }
 );
index 98306d7..49bf75b 100644 (file)
@@ -12,6 +12,57 @@ __PACKAGE__->mk_accessors( qw[ context parser ] );
 
 our $VERSION = 0.7;
 
+=head1 NAME
+
+HTTP::Body - HTTP Body Parser
+
+=head1 SYNOPSIS
+
+ use HTTP::Body;
+    
+ sub handler : method {
+     my ( $class, $r ) = @_;
+
+     my $content_type   = $r->headers_in->get('Content-Type');
+     my $content_length = $r->headers_in->get('Content-Length');
+     
+     my $body   = HTTP::Body->new( $content_type, $content_length );
+     my $length = $content_length;
+
+     while ( $length ) {
+
+         $r->read( my $buffer, ( $length < 8192 ) ? $length : 8192 );
+
+         $length -= length($buffer);
+         
+         $body->add($buffer);
+     }
+     
+     my $uploads = $body->upload; # hashref
+     my $params  = $body->param;  # hashref
+     my $body    = $body->body;   # IO::Handle
+ }
+
+=head1 DESCRIPTION
+
+HTTP Body Parser.
+
+=head1 METHODS
+
+=over 4 
+
+=item new($hashref)
+
+Constructor taking arugments as a hashref. Requires a C<context> argument which
+isa L<HTTP::Body::Context> object, and optional C<bufsize> (integer) and 
+C<parser> (L<HTTP::Body::Parser>) arguments.
+
+If called with two arguments C<($content_type, $content_length), 
+L<HTTP::Body::Compat> will be used instead to maintain compatability with
+versions <= 0.6
+
+=cut
+
 sub new {
     my $class = ref $_[0] ? ref shift : shift;
     
@@ -63,12 +114,35 @@ sub initialize {
     return $self;
 }
 
+=item eos
+
+=cut
+
 sub eos {
     return shift->parser->eos;
 }
 
+=item put
+
+=cut
+
 sub put {
     return shift->parser->put(@_);
 }
 
+=back
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch@ngmedia.com>
+
+This pod written by Ash Berlin, C<ash@cpan.org>.
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify 
+it under the same terms as perl itself.
+
+=cut
+
 1;
index 63db5a2..68ab14b 100644 (file)
@@ -7,6 +7,53 @@ use base 'HTTP::Body';
 use Params::Validate    qw[];
 use HTTP::Body::Context qw[];
 
+=head1 NAME
+
+HTTP::Body::Compat - Backwards compataible HTTP Body Parser for versions <= 0.6
+
+=head1 SYNOPSIS
+
+   use HTTP::Body;
+   
+   sub handler : method {
+       my ( $class, $r ) = @_;
+
+       my $content_type   = $r->headers_in->get('Content-Type');
+       my $content_length = $r->headers_in->get('Content-Length');
+      
+       # Calling HTTP::Body->new this way will go into pre 0.7 compat mode
+       my $body   = HTTP::Body->new( $content_type, $content_length );
+       my $length = $content_length;
+
+       while ( $length ) {
+
+           $r->read( my $buffer, ( $length < 8192 ) ? $length : 8192 );
+
+           $length -= length($buffer);
+           
+           $body->add($buffer);
+       }
+       
+       my $uploads = $body->upload; # hashref
+       my $params  = $body->param;  # hashref
+       my $body    = $body->body;   # IO::Handle
+   }
+
+=head1 DESCRIPTION
+
+HTTP Body Parser.
+
+=head1 METHODS
+
+=over 4 
+
+=item new 
+
+Constructor. Takes content type and content length as parameters,
+returns a L<HTTP::Body::Compat> object.
+
+=cut
+
 sub new {
     my $class   = ref $_[0] ? ref shift : shift;
     my ( $content_type, $content_length ) = Params::Validate::validate_with(
@@ -34,6 +81,12 @@ sub new {
     return bless( {}, $class )->initialize( { context => $context } );
 }
 
+=item add 
+
+Add string to internal buffer. Returns length before adding string.
+
+=cut
+
 sub add {
     my $self = shift;
     
@@ -51,6 +104,12 @@ sub add {
     return ( $self->length - $self->content_length );
 }
 
+=item body
+
+accessor for the body
+
+=cut
+
 sub body {
     return $_[0]->context->content;
 }
@@ -59,10 +118,22 @@ sub buffer {
     return '';
 }
 
+=item content_length
+
+Read-only accessor for content legnth
+
+=cut
+
 sub content_length {
     return $_[0]->context->content_length;
 }
 
+=item content_type
+
+Read-only accessor for content type
+
+=cut
+
 sub content_type {
     return $_[0]->context->content_type;
 }
@@ -75,6 +146,12 @@ sub state {
     return 'done';
 }
 
+=item param
+
+Accessor for HTTP parameters
+
+=cut
+
 sub param {
     my $self = shift;
     
@@ -85,6 +162,10 @@ sub param {
     return scalar $self->context->param->as_hash;
 }
 
+=iteam upload
+
+=cut
+
 sub upload {
     my $self = shift;
     
@@ -95,4 +176,19 @@ sub upload {
     return scalar $self->context->upload->as_hash;
 }
 
+=back
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch@ngmedia.com>
+
+This pod written by Ash Berlin, C<ash@cpan.org>.
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify 
+it under the same terms as perl itself.
+
+=cut
+
 1;
index 4eea210..5295a7b 100644 (file)
@@ -11,6 +11,32 @@ use Scalar::Util     qw[];
 
 __PACKAGE__->mk_accessors( qw[ content headers param upload ] );
 
+=head1 NAME
+
+HTTP::Body::Context
+
+=head1 METHODS
+
+=over
+
+=item new($hashref)
+
+Constructor. Takes the following arguments in a hashref:
+
+=over
+
+=item headers
+
+HTTP::Headers object, or an array or hashref
+
+=item param (optional)
+
+=item upload (optional)
+
+=back
+
+=cut
+
 sub new {
     my $class  = ref $_[0] ? ref shift : shift;
     my $params = Params::Validate::validate_with(
@@ -66,18 +92,45 @@ sub initialize {
     return $self;
 }
 
+=item context_length
+
+=cut
+
 sub content_length {
     return shift->headers->content_length(@_);
 }
 
+=item content_type
+
+=cut
+
 sub content_type {
     return shift->headers->content_type(@_);
 }
 
+=item header
+
+=cut
+
 sub header {
     return shift->headers->header(@_);
 }
 
+=back
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch@ngmedia.com>
+
+This pod written by Ash Berlin, C<ash@cpan.org>.
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify 
+it under the same terms as perl itself.
+
+=cut
+
 1;
 
 __END__
index 63730f5..7a16350 100644 (file)
@@ -26,6 +26,20 @@ __PACKAGE__->register_parser( 'application/octet-stream'          => 'HTTP::Body
 __PACKAGE__->register_parser( 'application/x-www-form-urlencoded' => 'HTTP::Body::Parser::UrlEncoded' );
 __PACKAGE__->register_parser( 'multipart/form-data'               => 'HTTP::Body::Parser::MultiPart'   );
 
+=head1 NAME
+
+HTTP::Body::Parser
+
+=head1 METHODS
+
+=over 4
+
+=item new($hashref)
+
+Constructor.
+
+=cut
+
 sub new {
     my $class  = ref $_[0] ? ref shift : shift;
     my $params = Params::Validate::validate_with(
@@ -127,4 +141,19 @@ sub put {
     return $self->parse;
 }
 
+=back
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch@ngmedia.com>
+
+This pod written by Ash Berlin, C<ash@cpan.org>.
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify 
+it under the same terms as perl itself.
+
+=cut
+
 1;
index 75a7f89..b7b2909 100644 (file)
@@ -3,21 +3,29 @@
 use strict;
 use warnings;
 
-use Test::More tests => 55;
+use Test::More;
+
+eval { require YAML; import YAML 'LoadFile'; };
+if ($@) {
+  eval { require YAML::Syck; import YAML::Syck 'LoadFile'; }
+}
+
+plan skip_all => 'Tests need YAML or YAML::Syck' if $@;
+
+plan tests => 55;
 
 use Cwd;
 use HTTP::Body;
 use File::Spec::Functions;
 use IO::File;
-use YAML;
 
 my $path = catdir( getcwd(), 't', 'data', 'multipart' );
 
 for ( my $i = 1; $i <= 11; $i++ ) {
 
     my $test    = sprintf( "%.3d", $i );
-    my $headers = YAML::LoadFile( catfile( $path, "$test-headers.yml" ) );
-    my $results = YAML::LoadFile( catfile( $path, "$test-results.yml" ) );
+    my $headers = LoadFile( catfile( $path, "$test-headers.yml" ) );
+    my $results = LoadFile( catfile( $path, "$test-results.yml" ) );
     my $content = IO::File->new( catfile( $path, "$test-content.dat" ) );
     my $body    = HTTP::Body->new( $headers->{'Content-Type'}, $headers->{'Content-Length'} );
 
index afcc020..6d0d3ca 100644 (file)
@@ -3,13 +3,21 @@
 use strict;
 use warnings;
 
-use Test::More tests => 5;
+use Test::More 
+
+eval { require YAML; import YAML 'LoadFile'; };
+if ($@) {
+  eval { require YAML::Syck; import YAML::Syck 'LoadFile'; }
+}
+
+plan skip_all => 'Tests need YAML or YAML::Syck' if $@;
+
+plan tests => 5;
 
 use Cwd;
 use HTTP::Body;
 use File::Spec::Functions;
 use IO::File;
-use YAML;
 
 my $path = catdir( getcwd(), 't', 'data', 'urlencoded' );
 
index 87331a2..1b7c567 100644 (file)
@@ -1,13 +1,21 @@
 use strict;
 use warnings;
 
-use Test::More tests => 8;
+use Test::More;
+
+eval { require YAML; import YAML 'LoadFile'; };
+if ($@) {
+  eval { require YAML::Syck; import YAML::Syck 'LoadFile'; }
+}
+
+plan skip_all => 'Tests need YAML or YAML::Syck' if $@;
+
+plan tests => 8;
 
 use Cwd;
 use HTTP::Body;
 use File::Spec::Functions;
 use IO::File;
-use YAML;
 
 my $path = catdir( getcwd(), 't', 'data', 'octetstream' );