[libanyevent-http-scopedclient-perl] 01/01: Imported Upstream version 0.0.5
Jonas Genannt
jonas at brachium-system.net
Fri Oct 18 20:08:45 UTC 2013
This is an automated email from the git hooks/post-receive script.
hggh-guest pushed a commit to branch master
in repository libanyevent-http-scopedclient-perl.
commit c8d5c1535e1cc6b985605d5511c2917e10d256f5
Author: Jonas Genannt <jonas at brachium-system.net>
Date: Fri Oct 18 21:56:28 2013 +0200
Imported Upstream version 0.0.5
---
Changes | 15 ++
INSTALL | 44 ++++++
LICENSE | 3 +
MANIFEST | 12 ++
META.yml | 31 +++++
Makefile.PL | 80 +++++++++++
README.md | 66 +++++++++
dist.ini | 18 +++
lib/AnyEvent/HTTP/ScopedClient.pm | 272 +++++++++++++++++++++++++++++++++++++
t/00-load.t | 5 +
t/scoped-client.t | 33 +++++
weaver.ini | 4 +
12 files changed, 583 insertions(+)
diff --git a/Changes b/Changes
new file mode 100644
index 0000000..416604c
--- /dev/null
+++ b/Changes
@@ -0,0 +1,15 @@
+go to https://github.com/aanoaa/AnyEvent-HTTP-ScopedClient/issues for the roadmap and known issues.
+
+v0.0.5 Sun Jun 23 22:03:40 2013 KST
+ - prevent 'newline' at 'Authorization' header
+
+v0.0.4 Thu May 30 11:13:44 2013 KST
+ - uri_escape_utf8(request_body)
+
+0.0.3 Fri Nov 30 10:04:43 2012 KST
+ - depend `Host` req header to `AnyEvent::HTTP`
+
+0.0.2 Thu Oct 11 10:59:18 2012 KST
+ - support editing multiple header at once
+ - enhancement test
+ - tidied all source code
diff --git a/INSTALL b/INSTALL
new file mode 100644
index 0000000..58ec908
--- /dev/null
+++ b/INSTALL
@@ -0,0 +1,44 @@
+
+This is the Perl distribution AnyEvent-HTTP-ScopedClient.
+
+Installing AnyEvent-HTTP-ScopedClient is straightforward.
+
+## Installation with cpanm
+
+If you have cpanm, you only need one line:
+
+ % cpanm AnyEvent::HTTP::ScopedClient
+
+If you are installing into a system-wide directory, you may need to pass the
+"-S" flag to cpanm, which uses sudo to install the module:
+
+ % cpanm -S AnyEvent::HTTP::ScopedClient
+
+## Installing with the CPAN shell
+
+Alternatively, if your CPAN shell is set up, you should just be able to do:
+
+ % cpan AnyEvent::HTTP::ScopedClient
+
+## Manual installation
+
+As a last resort, you can manually install it. Download the tarball, untar it,
+then build it:
+
+ % perl Makefile.PL
+ % make && make test
+
+Then install it:
+
+ % make install
+
+If you are installing into a system-wide directory, you may need to run:
+
+ % sudo make install
+
+## Documentation
+
+AnyEvent-HTTP-ScopedClient documentation is available as POD.
+You can run perldoc from a shell to read the documentation:
+
+ % perldoc AnyEvent::HTTP::ScopedClient
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..71a85be
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,3 @@
+This software is copyright (c) 2012 by Hyungsuk Hong.
+
+This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
diff --git a/MANIFEST b/MANIFEST
new file mode 100644
index 0000000..3926113
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,12 @@
+Changes
+INSTALL
+LICENSE
+MANIFEST
+META.yml
+Makefile.PL
+README.md
+dist.ini
+lib/AnyEvent/HTTP/ScopedClient.pm
+t/00-load.t
+t/scoped-client.t
+weaver.ini
diff --git a/META.yml b/META.yml
new file mode 100644
index 0000000..a6b4b1a
--- /dev/null
+++ b/META.yml
@@ -0,0 +1,31 @@
+---
+abstract: 'AnyEvent::HTTP wrapper'
+author:
+ - 'Hyungsuk Hong <hshong at perl.kr>'
+build_requires:
+ AnyEvent: 0
+ Test::More: 0
+ strict: 0
+ utf8: 0
+ warnings: 0
+configure_requires:
+ ExtUtils::MakeMaker: 6.30
+dynamic_config: 0
+generated_by: 'Dist::Zilla version 4.300034, CPAN::Meta::Converter version 2.131560'
+license: perl
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+name: AnyEvent-HTTP-ScopedClient
+requires:
+ AnyEvent::HTTP: 0
+ Encode: 0
+ HTTP::Request: 0
+ MIME::Base64: 0
+ Moose: 0
+ Try::Tiny: 0
+ URI: 0
+ URI::Escape: 0
+ URI::QueryParam: 0
+ namespace::autoclean: 0
+version: 0.0.5
diff --git a/Makefile.PL b/Makefile.PL
new file mode 100644
index 0000000..60dc698
--- /dev/null
+++ b/Makefile.PL
@@ -0,0 +1,80 @@
+
+use strict;
+use warnings;
+
+
+
+use ExtUtils::MakeMaker 6.30;
+
+
+
+my %WriteMakefileArgs = (
+ "ABSTRACT" => "AnyEvent::HTTP wrapper",
+ "AUTHOR" => "Hyungsuk Hong <hshong\@perl.kr>",
+ "BUILD_REQUIRES" => {},
+ "CONFIGURE_REQUIRES" => {
+ "ExtUtils::MakeMaker" => "6.30"
+ },
+ "DISTNAME" => "AnyEvent-HTTP-ScopedClient",
+ "EXE_FILES" => [],
+ "LICENSE" => "perl",
+ "NAME" => "AnyEvent::HTTP::ScopedClient",
+ "PREREQ_PM" => {
+ "AnyEvent::HTTP" => 0,
+ "Encode" => 0,
+ "HTTP::Request" => 0,
+ "MIME::Base64" => 0,
+ "Moose" => 0,
+ "Try::Tiny" => 0,
+ "URI" => 0,
+ "URI::Escape" => 0,
+ "URI::QueryParam" => 0,
+ "namespace::autoclean" => 0
+ },
+ "TEST_REQUIRES" => {
+ "AnyEvent" => 0,
+ "Test::More" => 0,
+ "strict" => 0,
+ "utf8" => 0,
+ "warnings" => 0
+ },
+ "VERSION" => "0.0.5",
+ "test" => {
+ "TESTS" => "t/*.t"
+ }
+);
+
+
+unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) {
+ my $tr = delete $WriteMakefileArgs{TEST_REQUIRES};
+ my $br = $WriteMakefileArgs{BUILD_REQUIRES};
+ for my $mod ( keys %$tr ) {
+ if ( exists $br->{$mod} ) {
+ $br->{$mod} = $tr->{$mod} if $tr->{$mod} > $br->{$mod};
+ }
+ else {
+ $br->{$mod} = $tr->{$mod};
+ }
+ }
+}
+
+unless ( eval { ExtUtils::MakeMaker->VERSION(6.56) } ) {
+ my $br = delete $WriteMakefileArgs{BUILD_REQUIRES};
+ my $pp = $WriteMakefileArgs{PREREQ_PM};
+ for my $mod ( keys %$br ) {
+ if ( exists $pp->{$mod} ) {
+ $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod};
+ }
+ else {
+ $pp->{$mod} = $br->{$mod};
+ }
+ }
+}
+
+delete $WriteMakefileArgs{CONFIGURE_REQUIRES}
+ unless eval { ExtUtils::MakeMaker->VERSION(6.52) };
+
+WriteMakefile(%WriteMakefileArgs);
+
+
+
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..971d30f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,66 @@
+## Scoped HTTP Client for Perl ##
+
+Yet another [AnyEvent::HTTP](http://search.cpan.org/~mlehmann/AnyEvent-HTTP/HTTP.pm) based client.
+
+stolen from [Scoped HTTP Client for Node.js](https://github.com/technoweenie/node-scoped-http-client)
+
+```perl
+use AnyEvent;
+use AnyEvent::HTTP::ScopedClient;
+my $client = AnyEvent::HTTP::ScopedClient->new('http://example.com');
+$client->request('GET', sub {
+ my ($body, $hdr) = @_; # $body is undef if error occured
+ return if ( !$body || !$hdr->{Status} =~ /^2/ );
+ # do something;
+});
+
+# shorcut for GET
+$client->get(sub {
+ my ($body, $hdr) = @_; # $body is undef if error occured
+ return if ( !$body || !$hdr->{Status} =~ /^2/ );
+ # do something;
+});
+
+# Content-Type: application/x-www-form-urlencoded
+$client->post(
+ { foo => 1, bar => 2 }, # note this.
+ sub {
+ my ($body, $hdr) = @_; # $body is undef if error occured
+ return if ( !$body || !$hdr->{Status} =~ /^2/ );
+ # do something;
+ }
+);
+
+# application/x-www-form-urlencoded post request
+$client->post(
+ "foo=1&bar=2" # and note this.
+ sub {
+ my ($body, $hdr) = @_; # $body is undef if error occured
+ return if ( !$body || !$hdr->{Status} =~ /^2/ );
+ # do something;
+ }
+);
+
+# Content-Type: application/json
+use JSON::XS;
+$client->header('Content-Type', 'application/json')
+ ->post(
+ encode_json({ foo => 1 }),
+ sub {
+ my ($body, $hdr) = @_; # $body is undef if error occured
+ return if ( !$body || !$hdr->{Status} =~ /^2/ );
+ # do something;
+ }
+ );
+
+$client->header('Accept', 'application/json')
+ ->query({ key => 'value' })
+ ->query('key', 'value')
+ ->get(sub {
+ my ($body, $hdr) = @_; # $body is undef if error occured
+ return if ( !$body || !$hdr->{Status} =~ /^2/ );
+ # do something;
+});
+
+AnyEvent->condvar->recv;
+```
diff --git a/dist.ini b/dist.ini
new file mode 100644
index 0000000..2f2f6b4
--- /dev/null
+++ b/dist.ini
@@ -0,0 +1,18 @@
+name = AnyEvent-HTTP-ScopedClient
+abstract = AnyEvent::HTTP wrapper
+author = Hyungsuk Hong <hshong at perl.kr>
+license = Perl_5
+copyright_holder = Hyungsuk Hong
+copyright_year = 2012
+version = 0.0.5
+
+[@Filter]
+-bundle = @Basic
+-remove = License
+-remove = Readme
+option = for_basic
+[PodWeaver]
+[AutoPrereqs]
+[PkgVersion]
+[InstallGuide]
+;[ReadmeMarkdownFromPod]
diff --git a/lib/AnyEvent/HTTP/ScopedClient.pm b/lib/AnyEvent/HTTP/ScopedClient.pm
new file mode 100644
index 0000000..7551a77
--- /dev/null
+++ b/lib/AnyEvent/HTTP/ScopedClient.pm
@@ -0,0 +1,272 @@
+package AnyEvent::HTTP::ScopedClient;
+{
+ $AnyEvent::HTTP::ScopedClient::VERSION = '0.0.5';
+}
+
+# ABSTRACT: L<AnyEvent> based L<https://github.com/technoweenie/node-scoped-http-client>
+
+use Moose;
+use namespace::autoclean;
+
+use URI;
+use Try::Tiny;
+use MIME::Base64;
+use HTTP::Request;
+use Encode qw/encode_utf8/;
+use AnyEvent::HTTP;
+use URI::QueryParam;
+use URI::Escape;
+
+has 'options' => (
+ is => 'ro',
+ isa => 'HashRef',
+);
+
+sub request {
+ my ( $self, $method, $reqBody, $callback ) = @_;
+ if ( 'CODE' eq ref($reqBody) ) {
+ $callback = $reqBody;
+ undef $reqBody;
+ }
+
+ my %options = %{ $self->options };
+ try {
+ my %headers = %{ $options{headers} };
+
+ if ( 'HASH' eq ref($reqBody) ) {
+ my @pair;
+
+ # push @pair, "$_=$reqBody->{$_}" for ( keys %$reqBody );
+ push @pair, "$_=" . uri_escape_utf8( $reqBody->{$_} )
+ for ( keys %$reqBody );
+ $reqBody = join( '&', @pair );
+ }
+
+ my $sendingData
+ = ( $method =~ m/^P/ && $reqBody && length $reqBody > 0 ) ? 1 : 0;
+ $headers{'Content-Length'} = length $reqBody if $sendingData;
+ $headers{'Content-Type'} = 'application/x-www-form-urlencoded'
+ if ( $sendingData && !$headers{'Content-Type'} );
+
+ if ( $options{auth} ) {
+ $headers{Authorization}
+ = 'Basic ' . encode_base64( $options{auth}, '' );
+ }
+
+ if ( $ENV{DEBUG} ) {
+ print "$method " . $self->options->{url} . "\n";
+ while ( my ( $k, $v ) = each %headers ) {
+ print "$k: $v\n";
+ }
+
+ print "\n";
+ print "$reqBody\n" if $sendingData;
+ }
+
+ http_request(
+ $method,
+ $options{url},
+ headers => \%headers,
+ body => $sendingData ? encode_utf8($reqBody) : undef,
+ $callback
+ );
+ }
+ catch {
+ $callback->($_) if $callback;
+ };
+
+ return $self;
+}
+
+sub fullPath {
+ my ( $self, $p ) = @_;
+}
+
+sub scope {
+ my ( $self, $url, $options, $callback ) = @_;
+}
+
+sub join {
+ my ( $self, $suffix ) = @_;
+}
+
+sub path {
+ my ( $self, $p ) = @_;
+}
+
+sub query {
+ my ( $self, $key, $value ) = @_;
+ if ( 'HASH' eq ref $key ) {
+ while ( my ( $k, $v ) = each %$key ) {
+ $self->options->{url}->query_param( $k => $v );
+ }
+ }
+ else {
+ $self->options->{url}->query_param( $key => $value );
+ }
+ return $self;
+}
+
+sub host {
+ my ( $self, $h ) = @_;
+}
+
+sub protocol {
+ my ( $self, $p ) = @_;
+}
+
+sub auth {
+ my ( $self, $user, $pass ) = @_;
+ if ( !$user ) {
+ $self->options->{auth} = undef;
+ }
+ elsif ( !$pass && $user =~ m/:/ ) {
+ $self->options->{auth} = $user;
+ }
+ else {
+ $self->options->{auth} = "$user:$pass";
+ }
+
+ return $self;
+}
+
+sub header {
+ my ( $self, $name, $value ) = @_;
+ if ( 'HASH' eq ref $name ) {
+ while ( my ( $k, $v ) = each %$name ) {
+ $self->options->{headers}{$k} = $v;
+ }
+ }
+ else {
+ $self->options->{headers}{$name} = $value;
+ }
+
+ return $self;
+}
+
+sub headers {
+ my ( $self, $h ) = @_;
+}
+
+sub buildOptions {
+ my ( $self, $url, $params ) = @_;
+ $params->{options}{url} = URI->new($url);
+ $params->{options}{headers} ||= {};
+}
+
+sub BUILDARGS {
+ my ( $self, $url, %params ) = @_;
+ $self->buildOptions( $url, \%params );
+ return \%params;
+}
+
+sub get { shift->request( 'GET', @_ ) }
+sub post { shift->request( 'POST', @_ ) }
+sub patch { shift->request( 'PATCH', @_ ) }
+sub put { shift->request( 'PUT', @_ ) }
+sub delete { shift->request( 'DELETE', @_ ) }
+sub head { shift->request( 'HEAD', @_ ) }
+
+__PACKAGE__->meta->make_immutable;
+
+1;
+
+__END__
+
+=pod
+
+=encoding utf-8
+
+=head1 NAME
+
+AnyEvent::HTTP::ScopedClient - L<AnyEvent> based L<https://github.com/technoweenie/node-scoped-http-client>
+
+=head1 VERSION
+
+version 0.0.5
+
+=head1 SYNOPSIS
+
+ my $client = AnyEvent::HTTP::ScopedClient->new('http://example.com');
+ $client->request('GET', sub {
+ my ($body, $hdr) = @_; # $body is undef if error occured
+ return if ( !$body || $hdr->{Status} !~ /^2/ );
+ # do something;
+ });
+
+ # shorcut for GET
+ $client->get(sub {
+ my ($body, $hdr) = @_;
+ # ...
+ });
+
+ # Content-Type: application/x-www-form-urlencoded
+ $client->post(
+ { foo => 1, bar => 2 }, # note this.
+ sub {
+ my ($body, $hdr) = @_;
+ # ...
+ }
+ );
+
+ # application/x-www-form-urlencoded post request
+ $client->post(
+ "foo=1&bar=2" # and note this.
+ sub {
+ my ($body, $hdr) = @_;
+ # ...
+ }
+ );
+
+ # Content-Type: application/json
+ use JSON::XS;
+ $client->header('Content-Type', 'application/json')
+ ->post(
+ encode_json({ foo => 1 }),
+ sub {
+ my ($body, $hdr) = @_;
+ # ...
+ }
+ );
+
+ $client->header('Accept', 'application/json')
+ ->query({ key => 'value' })
+ ->query('key', 'value')
+ ->get(
+ sub {
+ my ($body, $hdr) = @_;
+ # ...
+ }
+ );
+
+ # headers at once
+ $client->header({
+ Accept => '*/*',
+ Authorization => 'Basic abcd'
+ })->get(
+ sub {
+ my ($body, $hdr) = @_;
+ # ...
+ }
+ );
+
+=head1 DESCRIPTION
+
+L<AnyEvent::HTTP> wrapper
+
+=head1 SEE ALSO
+
+L<https://github.com/technoweenie/node-scoped-http-client>
+
+=head1 AUTHOR
+
+Hyungsuk Hong <hshong at perl.kr>
+
+=head1 COPYRIGHT AND LICENSE
+
+This software is copyright (c) 2012 by Hyungsuk Hong.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=cut
diff --git a/t/00-load.t b/t/00-load.t
new file mode 100644
index 0000000..5d3a6c0
--- /dev/null
+++ b/t/00-load.t
@@ -0,0 +1,5 @@
+use strict;
+use warnings;
+
+use Test::More tests => 1;
+BEGIN { use_ok('AnyEvent::HTTP::ScopedClient') }
diff --git a/t/scoped-client.t b/t/scoped-client.t
new file mode 100644
index 0000000..415edaf
--- /dev/null
+++ b/t/scoped-client.t
@@ -0,0 +1,33 @@
+use utf8;
+use strict;
+use warnings;
+use Test::More tests => 2;
+use AnyEvent;
+
+use AnyEvent::HTTP::ScopedClient;
+
+my $cv = AE::cv;
+my $http = AnyEvent::HTTP::ScopedClient->new('http://www.naver.com/');
+
+$cv->begin;
+$http->header( { 'Accept' => '*/*' } )->get(
+ sub {
+ my ( $body, $hdr ) = @_;
+ diag("$hdr->{Status}: $hdr->{Reason}") if $hdr->{Status} !~ /^2/;
+ is( $hdr->{Status}, 200, 'GET request' );
+ $cv->end;
+ }
+);
+
+$cv->begin;
+$http->post(
+ { foo => 'bar', bar => 'baz', baz => '유니코드' },
+ sub {
+ my ( $body, $hdr ) = @_;
+ diag("$hdr->{Status}: $hdr->{Reason}") if $hdr->{Status} !~ /^2/;
+ is( $hdr->{Status}, 200, 'POST request' );
+ $cv->end;
+ }
+);
+
+$cv->recv;
diff --git a/weaver.ini b/weaver.ini
new file mode 100644
index 0000000..a0adbc0
--- /dev/null
+++ b/weaver.ini
@@ -0,0 +1,4 @@
+[@Default]
+
+[-Encoding]
+encoding = utf-8
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libanyevent-http-scopedclient-perl.git
More information about the Pkg-perl-cvs-commits
mailing list