[Bps-public-commit] plient branch, master, updated. 2ec0038f6c50e3a1259484f0b7eb747c3b939392

? sunnavy sunnavy at bestpractical.com
Mon May 3 22:48:14 EDT 2010


The branch, master has been updated
       via  2ec0038f6c50e3a1259484f0b7eb747c3b939392 (commit)
       via  66a4a9e1c8caf11ebc1fa2ae7d01797941080e02 (commit)
       via  21e3c9c6cd0beedb7c2cedbb5a9bb8d7f643557d (commit)
      from  a0040f2c11f6fa549756641b8efec40130bfffa3 (commit)

Summary of changes:
 bin/plient                     |   10 ++++++++--
 lib/Plient.pm                  |   19 +++++++++++++++----
 lib/Plient/Handler/HTTPLite.pm |    2 ++
 lib/Plient/Handler/LWP.pm      |    2 ++
 4 files changed, 27 insertions(+), 6 deletions(-)

- Log -----------------------------------------------------------------
commit 21e3c9c6cd0beedb7c2cedbb5a9bb8d7f643557d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue May 4 08:37:18 2010 +0800

    add output to file option

diff --git a/bin/plient b/bin/plient
index 617168f..2026ccd 100755
--- a/bin/plient
+++ b/bin/plient
@@ -7,7 +7,7 @@ Plient->import( 'plient', 'plient_support' );
 
 my %args;
 
-GetOptions( \%args, 'help|h', 'support|s=s', 'request|X=s', )
+GetOptions( \%args, 'help|h', 'support|s=s', 'request|X=s', 'output|o=s' )
   or die 'unknown option';
 
 my $USAGE =<<EOF;
@@ -16,6 +16,7 @@ EXAMPLES:
     plient --support http_get                       # check is support HTTP GET
     plient -s http_get                              # ditto
     plient http://cpan.org/                         # fetch http://cpan.org
+    plient -o /tmp/cpan.html http://cpan.org/       # write to file
 EOF
 
 if ( $args{help} ) {
@@ -40,6 +41,11 @@ my $method = $args{'request'} || 'get';
 
 for my $uri (@uri) {
     $uri = 'http://' . $uri unless $uri =~ /^\w+:/;
-    print plient( $method, $uri );
+    if ( $args{output} ) {
+        plient( $method, $uri, { output_file => $args{output} } );
+    }
+    else {
+        print plient( $method, $uri );
+    }
 }
 
diff --git a/lib/Plient.pm b/lib/Plient.pm
index 03d8ee2..2449366 100644
--- a/lib/Plient.pm
+++ b/lib/Plient.pm
@@ -26,7 +26,15 @@ sub plient {
 
     my $sub = dispatch( $method, $uri, $args );
     if ( $sub ) {
-        $sub->();
+        if ( $args->{output_file} ) {
+            open my $fh, '>', $args->{output_file} or die $!;
+            print $fh $sub->();
+            close $fh;
+            return 1;
+        }
+        else {
+            return $sub->();
+        }
     }
     else {
         warn "failed to $method on $uri"; 

commit 66a4a9e1c8caf11ebc1fa2ae7d01797941080e02
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue May 4 10:09:57 2010 +0800

    respect env proxy settings

diff --git a/lib/Plient/Handler/HTTPLite.pm b/lib/Plient/Handler/HTTPLite.pm
index cf316eb..cf0e578 100644
--- a/lib/Plient/Handler/HTTPLite.pm
+++ b/lib/Plient/Handler/HTTPLite.pm
@@ -21,6 +21,7 @@ sub init {
         my ( $uri, $args ) = @_;
         my $http  = HTTP::Lite->new;
         add_headers( $http, $args->{headers} ) if $args->{headers};
+        $http->proxy( $ENV{http_proxy} ) if $ENV{http_proxy};
         my $res = $http->request($uri) || '';
 
         if ( $res == 200 || $res == 301 || $res == 302 ) {
@@ -37,6 +38,7 @@ sub init {
     $method{http_post} = sub {
         my ( $uri, $args ) = @_;
         my $http  = HTTP::Lite->new;
+        $http->proxy( $ENV{http_proxy} ) if $ENV{http_proxy};
         add_headers( $http, $args->{headers} ) if $args->{headers};
         $http->prepare_post( $args->{body} ) if $args->{body};
         my $res = $http->request($uri) || '';
diff --git a/lib/Plient/Handler/LWP.pm b/lib/Plient/Handler/LWP.pm
index 2eb1cd1..81c91ea 100644
--- a/lib/Plient/Handler/LWP.pm
+++ b/lib/Plient/Handler/LWP.pm
@@ -29,6 +29,7 @@ sub init {
 
         # XXX TODO tweak the new arguments
         my $ua  = LWP::UserAgent->new;
+        $ua->env_proxy;
         add_headers( $ua, $args->{headers} ) if $args->{headers};
         my $res = $ua->get($uri);
         if ( $res->is_success ) {
@@ -45,6 +46,7 @@ sub init {
 
         # XXX TODO tweak the new arguments
         my $ua  = LWP::UserAgent->new;
+        $ua->env_proxy;
         add_headers( $ua, $args->{headers} ) if $args->{headers};
         my $res =
           $ua->post( $uri,

commit 2ec0038f6c50e3a1259484f0b7eb747c3b939392
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Tue May 4 10:18:42 2010 +0800

    pod tweak

diff --git a/lib/Plient.pm b/lib/Plient.pm
index 2449366..5177a47 100644
--- a/lib/Plient.pm
+++ b/lib/Plient.pm
@@ -260,12 +260,15 @@ Plient - the uniform way to use curl, wget, LWP, HTTP::Lite, etc.
 C<Plient> is a wrapper to clients like C<curl>, C<wget>, C<LWP> and
 C<HTTP::Lite>, aiming to supply a uniform way for users.
 
-It's useful if you don't want to bind your applications to only one client.
-e.g. forcing users to install C<curl> even when some of them already have C<wget>
-installed.
+It's intended to use in situations where you don't want to bind your applications
+to one specific client. e.g. forcing users to install C<curl> even when some of
+them already have C<wget> installed.
 
 C<Plient> will try its best to use clients available.
 
+C<Plient> is a very young project, only a subset of HTTP functionality is
+implemented currently.
+
 =head1 INTERFACE
 
 =head2 plient( $method, $uri, $args )

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list