Xu Xiaodong avatar Xu Xiaodong committed e9c006c

just a small update

Comments (0)

Files changed (1)

 # author:    Xu Xiaodong <xxdlhy@gmail.com>
 # license:   GPL
 # created:   2011 Apr 13
-# modified:  2011 Apr 28
+# modified:  2011 Aug 15
 #
 
-use Modern::Perl;
+use strict;
+use warnings;
+
 use LWP::UserAgent;
 use MIME::Base64;
 use Getopt::Long;
 my ( $name, $desc, $is_private ) = ( '', '', 0 );
 
 GetOptions(
-    'n|name=s' => \$name,
-    'd|desc=s' => \$desc,
-    'p|priv'   => \$is_private,
+  'n|name=s' => \$name,
+  'd|desc=s' => \$desc,
+  'p|priv'   => \$is_private,
 );
 
 if ($name) {
-    create( $name, $desc, $is_private );
-    init($name);
+  create( $name, $desc, $is_private );
+  init($name);
 }
 else {
-    die <<"USAGE";
+  die <<"USAGE";
 Usage: $0 -n <name> [-d <desc>] [-p]
 
     -n, --name name         Repository name
 }
 
 sub account {
-    my ( $user, $pass );
+  my ( $user, $pass );
 
-    open my ($in_fh), '<', "$ENV{HOME}/.hgrc"
-        or die "Can't open .hgrc: $!\n";
+  open my ($in_fh), '<', "$ENV{HOME}/.hgrc"
+    or die "Can't open .hgrc: $!\n";
 
-    while (<$in_fh>) {
-        next if /\A[#;]/;
-        next if /\A\s*\Z/;
+  while (<$in_fh>) {
+    next if /\A[#;]/;
+    next if /\A\s*\Z/;
 
-        $user = $1 if /\.username\s+=\s+(.*)\Z/;
-        $pass = $1 if /\.password\s+=\s+(.*)\Z/;
-    }
+    $user = $1 if /\.username\s+=\s+(.*)\Z/;
+    $pass = $1 if /\.password\s+=\s+(.*)\Z/;
+  }
 
-    close $in_fh;
+  close $in_fh;
 
-    return ( $user, $pass );
+  return ( $user, $pass );
 }
 
 sub create {
-    my ( $name, $desc, $is_private ) = @_;
-    my %param;
+  my ( $name, $desc, $is_private ) = @_;
+  my %param;
 
-    $param{name}        = $name       if $name;
-    $param{description} = $desc       if $desc;
-    $param{is_private}  = $is_private if $is_private;
+  $param{name}        = $name       if $name;
+  $param{description} = $desc       if $desc;
+  $param{is_private}  = $is_private if $is_private;
 
-    my $url = 'https://api.bitbucket.org/1.0/repositories/';
-    my ( $user, $pass ) = account();
-    my $ua = LWP::UserAgent->new();
+  my $url = 'https://api.bitbucket.org/1.0/repositories/';
+  my ( $user, $pass ) = account();
+  my $ua = LWP::UserAgent->new();
 
-    $ua->default_header(
-        authorization => 'Basic ' . encode_base64( $user . ':' . $pass ) );
+  $ua->default_header(
+    authorization => 'Basic ' . encode_base64( $user . ':' . $pass ) );
 
-    my $resp = $ua->post( $url, \%param );
+  my $resp = $ua->post( $url, \%param );
 
-    if ( $resp->is_success ) {
-        say $resp->decoded_content;
-    }
-    else {
-        die $resp->status_line;
-    }
+  if ( $resp->is_success ) {
+    say $resp->decoded_content;
+  }
+  else {
+    die $resp->status_line;
+  }
 }
 
 sub init {
-    my ($repo) = @_;
-    my $user   = (account())[0];
-    my $url    = "https://bitbucket.org/$user/$repo";
+  my ($repo) = @_;
+  my $user   = ( account() )[0];
+  my $url    = "https://bitbucket.org/$user/$repo";
 
-    system 'hg', 'clone', $url;
+  system 'hg', 'clone', $url;
 }
 
-# vim: ai:et:ts=4:sw=4:tw=78:ft=perl
+# vim: ai:et:ts=2:sw=2:tw=78:ft=perl
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.