[Catalyst-commits] r6185 - in trunk/HTTP-Body: . lib/HTTP
lib/HTTP/Body t
ash at dev.catalyst.perl.org
ash at dev.catalyst.perl.org
Fri Mar 23 15:03:19 GMT 2007
Author: ash
Date: 2007-03-23 15:03:19 +0000 (Fri, 23 Mar 2007)
New Revision: 6185
Removed:
trunk/HTTP-Body/MANIFEST
trunk/HTTP-Body/META.yml
Modified:
trunk/HTTP-Body/Changes
trunk/HTTP-Body/Makefile.PL
trunk/HTTP-Body/lib/HTTP/Body.pm
trunk/HTTP-Body/lib/HTTP/Body/Compat.pm
trunk/HTTP-Body/lib/HTTP/Body/Context.pm
trunk/HTTP-Body/lib/HTTP/Body/Parser.pm
trunk/HTTP-Body/t/04multipart.t
trunk/HTTP-Body/t/05urlencoded.t
trunk/HTTP-Body/t/06octetstream.t
Log:
Minimal pod, and removed req on YAML - tests will skip all if not found
Modified: trunk/HTTP-Body/Changes
===================================================================
--- trunk/HTTP-Body/Changes 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/Changes 2007-03-23 15:03:19 UTC (rev 6185)
@@ -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 at cpan.org>.
- Fixed YAML prereq, reported by Jess Robinson
Deleted: trunk/HTTP-Body/MANIFEST
===================================================================
--- trunk/HTTP-Body/MANIFEST 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/MANIFEST 2007-03-23 15:03:19 UTC (rev 6185)
@@ -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
Deleted: trunk/HTTP-Body/META.yml
===================================================================
--- trunk/HTTP-Body/META.yml 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/META.yml 2007-03-23 15:03:19 UTC (rev 6185)
@@ -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
Modified: trunk/HTTP-Body/Makefile.PL
===================================================================
--- trunk/HTTP-Body/Makefile.PL 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/Makefile.PL 2007-03-23 15:03:19 UTC (rev 6185)
@@ -15,6 +15,5 @@
IO::File => 0,
Params::Validate => 0,
Scalar::Util => 0,
- YAML => '0.39'
}
);
Modified: trunk/HTTP-Body/lib/HTTP/Body/Compat.pm
===================================================================
--- trunk/HTTP-Body/lib/HTTP/Body/Compat.pm 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/lib/HTTP/Body/Compat.pm 2007-03-23 15:03:19 UTC (rev 6185)
@@ -7,6 +7,53 @@
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 @@
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 @@
return ( $self->length - $self->content_length );
}
+=item body
+
+accessor for the body
+
+=cut
+
sub body {
return $_[0]->context->content;
}
@@ -59,10 +118,22 @@
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 @@
return 'done';
}
+=item param
+
+Accessor for HTTP parameters
+
+=cut
+
sub param {
my $self = shift;
@@ -85,6 +162,10 @@
return scalar $self->context->param->as_hash;
}
+=iteam upload
+
+=cut
+
sub upload {
my $self = shift;
@@ -95,4 +176,19 @@
return scalar $self->context->upload->as_hash;
}
+=back
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch at ngmedia.com>
+
+This pod written by Ash Berlin, C<ash at 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;
Modified: trunk/HTTP-Body/lib/HTTP/Body/Context.pm
===================================================================
--- trunk/HTTP-Body/lib/HTTP/Body/Context.pm 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/lib/HTTP/Body/Context.pm 2007-03-23 15:03:19 UTC (rev 6185)
@@ -11,6 +11,32 @@
__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 @@
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 at ngmedia.com>
+
+This pod written by Ash Berlin, C<ash at 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__
Modified: trunk/HTTP-Body/lib/HTTP/Body/Parser.pm
===================================================================
--- trunk/HTTP-Body/lib/HTTP/Body/Parser.pm 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/lib/HTTP/Body/Parser.pm 2007-03-23 15:03:19 UTC (rev 6185)
@@ -26,6 +26,20 @@
__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 @@
return $self->parse;
}
+=back
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch at ngmedia.com>
+
+This pod written by Ash Berlin, C<ash at 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;
Modified: trunk/HTTP-Body/lib/HTTP/Body.pm
===================================================================
--- trunk/HTTP-Body/lib/HTTP/Body.pm 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/lib/HTTP/Body.pm 2007-03-23 15:03:19 UTC (rev 6185)
@@ -12,6 +12,57 @@
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 @@
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 at ngmedia.com>
+
+This pod written by Ash Berlin, C<ash at 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;
Modified: trunk/HTTP-Body/t/04multipart.t
===================================================================
--- trunk/HTTP-Body/t/04multipart.t 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/t/04multipart.t 2007-03-23 15:03:19 UTC (rev 6185)
@@ -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'} );
Modified: trunk/HTTP-Body/t/05urlencoded.t
===================================================================
--- trunk/HTTP-Body/t/05urlencoded.t 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/t/05urlencoded.t 2007-03-23 15:03:19 UTC (rev 6185)
@@ -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' );
Modified: trunk/HTTP-Body/t/06octetstream.t
===================================================================
--- trunk/HTTP-Body/t/06octetstream.t 2007-03-23 14:23:10 UTC (rev 6184)
+++ trunk/HTTP-Body/t/06octetstream.t 2007-03-23 15:03:19 UTC (rev 6185)
@@ -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' );
More information about the Catalyst-commits
mailing list