[Bps-public-commit] plient branch, master, updated. 13e32bc84e7a70313fb9401e82d3687b3731fe0f
? sunnavy
sunnavy at bestpractical.com
Tue Nov 9 04:55:39 EST 2010
The branch, master has been updated
via 13e32bc84e7a70313fb9401e82d3687b3731fe0f (commit)
via 4d18076118d1ba0d13eaef5c322db8eb81fdb0a8 (commit)
via f325eda5419b10a8585600fc7085c3f1dffe852f (commit)
from df72602a5b61b5f5e251996315f573da7b35872d (commit)
Summary of changes:
bin/plient | 168 ++++++++++++++++++++++++++++---------------
lib/Plient.pm | 6 +-
lib/Plient/Handler/curl.pm | 3 +-
3 files changed, 114 insertions(+), 63 deletions(-)
- Log -----------------------------------------------------------------
commit f325eda5419b10a8585600fc7085c3f1dffe852f
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Nov 9 15:39:52 2010 +0800
warning fix
diff --git a/lib/Plient/Handler/curl.pm b/lib/Plient/Handler/curl.pm
index af303f9..b117ea2 100644
--- a/lib/Plient/Handler/curl.pm
+++ b/lib/Plient/Handler/curl.pm
@@ -138,7 +138,7 @@ sub translate_auth {
my $args = shift || {};
my $auth = '';
if ( $args->{user} && defined $args->{password} ) {
- my $method = lc $args->{auth_method} || 'basic';
+ my $method = lc( $args->{auth_method} || 'basic' );
if ( $method eq 'basic' ) {
$auth = " -u '$args->{user}:$args->{password}'";
}
@@ -150,6 +150,7 @@ sub translate_auth {
}
__PACKAGE__->_add_to_plient if $Plient::bundle_mode;
+
1;
__END__
commit 4d18076118d1ba0d13eaef5c322db8eb81fdb0a8
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Nov 9 15:41:06 2010 +0800
tweak warning msg a bit
diff --git a/lib/Plient.pm b/lib/Plient.pm
index 9f311d3..ea574bf 100644
--- a/lib/Plient.pm
+++ b/lib/Plient.pm
@@ -97,7 +97,7 @@ sub _extract_protocol {
return 'file';
}
else {
- warn "unsupported $uri";
+ warn "unsupported uri: $uri";
return;
}
}
@@ -119,7 +119,7 @@ sub _dispatch_protocol {
return 'Plient::Protocol::HTTPS';
}
else {
- warn "unsupported protocol";
+ warn "unsupported protocol: $protocol";
return;
}
}
@@ -147,7 +147,7 @@ sub dispatch {
return sub { $sub->( $uri, $args ) };
}
else {
- warn "unsupported $method";
+ warn "unsupported method: $method";
return;
}
}
commit 13e32bc84e7a70313fb9401e82d3687b3731fe0f
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Nov 9 15:41:44 2010 +0800
add interactive mode
diff --git a/bin/plient b/bin/plient
index 1b3ea32..b79c437 100755
--- a/bin/plient
+++ b/bin/plient
@@ -5,6 +5,8 @@ use Getopt::Long;
require Plient unless $ENV{PLIENT_BUNDLE_MODE};
require Plient::Util unless $ENV{PLIENT_BUNDLE_MODE};
Plient->import( 'plient', 'plient_support' );
+use Term::ReadLine;
+use Text::ParseWords;
my %args;
@@ -24,82 +26,120 @@ EXAMPLES:
plient -F foo=@/tmp/bar.log http://foo.org # post with file upload
EOF
-if ( $args{help} ) {
- print $USAGE;
- exit;
-}
-
if ( $args{support} ) {
- my ( $protocol, $method ) = split /_/, $args{support}, 2;
- print plient_support( $protocol, $method ) ? 'yes' : 'no';
- print "\n";
+ support( $args{support} );
exit;
}
-if ( !$ARGV[0] ) {
- print $USAGE;
- exit;
-}
+my $prompt = 'plient> ';
+my %actions = (
+ shell => \&shell,
+ support => \&support,
+ supports => \&support,
+ help => \&help,
+);
-if ( $args{data} && $args{form} ) {
- die "--data and --form can't be both set";
-}
+sub handler {
-my $method = $args{'request'} || 'get';
-$method = 'post' if $args{form} || $args{data};
-
-my @body;
-if ( $args{form} ) {
- for my $data ( ref $args{form} eq 'ARRAY' ? @{ $args{form} } : $args{form} )
- {
- push @body, map {
- my ( $k, $v ) = split /=/, $_, 2;
- $v =~ s/\^@// ? ( $k, { file => $v } ) : ( $k, $v )
- } split /;/, $data;
+ push @ARGV, 'shell' unless @ARGV; # default to interactive mode
+ shift @ARGV if ( $ARGV[0] eq 'plient' ); # ignore a leading 'rt'
+ if ( @ARGV ) {
+ if ( exists $actions{ lc $ARGV[0] } ) {
+ $actions{ lc shift @ARGV }->();
+ return 0;
+ }
+ else {
+ handle();
+ return 0;
+ }
+ }
+ else {
+ print STDERR "plient: unknown command '@ARGV'.\n";
+ print STDERR "plient: For help, run 'plient help'.\n";
+ return 1;
}
+
}
-elsif ( $args{data} ) {
-# can specify multiple times like -d foo=bar -d bar=baz
- for my $data ( ref $args{data} eq 'ARRAY' ? @{ $args{data} } : $args{data} )
- {
- push @body, map { split /=/, $_, 2 } split /;/, $data;
+
+exit handler();
+
+sub shell {
+ $| = 1;
+ my $term = Term::ReadLine->new( 'Plient' );
+ # I really don't like the underscores in the prompt
+ $term->ornaments(0);
+ while ( defined( $_ = $term->readline($prompt) ) ) {
+ next if /^#/ || /^\s*$/;
+ @ARGV = shellwords($_);
+ handler();
}
}
-my ( @uri ) = @ARGV;
-for my $uri (@uri) {
- $uri = 'http://' . $uri unless $uri =~ /^\w+:/;
- my ( $user, $password );
- if ($user) {
- ( $user, $password ) = split /:/, $args{user}, 2;
- while ( !defined $password ) {
- $password = prompt_password("password for $user:");
+sub handle {
+
+ if ( $args{data} && $args{form} ) {
+ die "--data and --form can't be both set";
+ }
+
+ my $method = $args{'request'} || 'get';
+ $method = 'post' if $args{form} || $args{data};
+
+ my @body;
+ if ( $args{form} ) {
+ for my $data (
+ ref $args{form} eq 'ARRAY' ? @{ $args{form} } : $args{form} )
+ {
+ push @body, map {
+ my ( $k, $v ) = split /=/, $_, 2;
+ $v =~ s/\^@// ? ( $k, { file => $v } ) : ( $k, $v )
+ } split /;/, $data;
}
}
+ elsif ( $args{data} ) {
- if ( $args{output} ) {
- plient(
- $method, $uri,
- {
- output_file => $args{output},
- user => $user,
- password => $password,
- $args{form} ? ( content_type => 'form-data' ) : (),
- $method =~ /post/i ? ( body => \@body ) : (),
- }
- );
+ # can specify multiple times like -d foo=bar -d bar=baz
+ for my $data (
+ ref $args{data} eq 'ARRAY' ? @{ $args{data} } : $args{data} )
+ {
+ push @body, map { split /=/, $_, 2 } split /;/, $data;
+ }
}
- else {
- print plient(
- $method, $uri,
- {
- user => $user,
- password => $password,
- $args{form} ? ( content_type => 'form-data' ) : (),
- $method =~ /post/i ? ( body => \@body ) : (),
+ my (@uri) = @ARGV;
+
+ for my $uri (@uri) {
+ $uri = 'http://' . $uri unless $uri =~ /^\w+:/;
+ my ( $user, $password );
+ if ($args{user}) {
+ ( $user, $password ) = split /:/, $args{user}, 2;
+ while ( !defined $password ) {
+ $password = prompt_password("password for $user:");
}
- );
+ }
+
+ if ( $args{output} ) {
+ plient(
+ $method, $uri,
+ {
+ output_file => $args{output},
+ user => $user,
+ password => $password,
+ $args{form} ? ( content_type => 'form-data' ) : (),
+ $method =~ /post/i ? ( body => \@body ) : (),
+ }
+ );
+ }
+ else {
+ print plient(
+ $method, $uri,
+ {
+ user => $user,
+ password => $password,
+ $args{form} ? ( content_type => 'form-data' ) : (),
+ $method =~ /post/i ? ( body => \@body ) : (),
+ }
+ );
+ }
}
}
@@ -131,3 +171,13 @@ sub prompt_password {
return $password;
}
+sub support {
+ my $value = shift;
+ my ( $protocol, $method ) = split /_/, $value || $ARGV[0];
+ print plient_support( $protocol, $method ) ? 'yes' : 'no';
+ print "\n";
+}
+
+sub help {
+ print $USAGE;
+}
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list