Skip to content

Commit

Permalink
removed prompt again
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 16, 2012
1 parent ec4d881 commit 4976aeb
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 71 deletions.
3 changes: 0 additions & 3 deletions Changes
@@ -1,9 +1,6 @@

3.48 2012-10-16
- Added prompt method to Mojo::ByteStream.
- Added prompt function to Mojo::Util. (jberger, sri)
- Improved Mojo::Content performance slightly.
- Improved cpanify command to prompt for password if necessary. (jberger)
- Improved documentation.
- Fixed memory leak in Mojo::Headers.

Expand Down
10 changes: 1 addition & 9 deletions lib/Mojo/ByteStream.pm
Expand Up @@ -11,7 +11,7 @@ our @EXPORT_OK = ('b');
# Turn most functions from Mojo::Util into methods
my @UTILS = (
qw(b64_decode b64_encode camelize decamelize hmac_md5_sum hmac_sha1_sum),
qw(html_escape html_unescape md5_bytes md5_sum prompt punycode_decode),
qw(html_escape html_unescape md5_bytes md5_sum punycode_decode),
qw(punycode_encode quote sha1_bytes sha1_sum slurp spurt squish trim),
qw(unquote url_escape url_unescape xml_escape xor_encode)
);
Expand Down Expand Up @@ -210,14 +210,6 @@ Generate binary MD5 checksum for bytestream with L<Mojo::Util/"md5_bytes">.
Generate MD5 checksum for bytestream with L<Mojo::Util/"md5_sum">.
=head2 C<prompt>
$stream = $stream->prompt;
Prompt user with L<Mojo::Util/"prompt">.
b('Password: ')->prompt->xor_encode('s3cret')->say;
=head2 C<punycode_decode>
$stream = $stream->punycode_decode;
Expand Down
22 changes: 3 additions & 19 deletions lib/Mojo/Util.pm
Expand Up @@ -40,9 +40,9 @@ $REVERSE{$ENTITIES{$_}} //= $_
our @EXPORT_OK = (
qw(b64_decode b64_encode camelize class_to_file class_to_path decamelize),
qw(decode encode get_line hmac_md5_sum hmac_sha1_sum html_escape),
qw(html_unescape md5_bytes md5_sum prompt punycode_decode punycode_encode),
qw(quote secure_compare sha1_bytes sha1_sum slurp spurt squish trim),
qw(unquote url_escape url_unescape xml_escape xor_encode)
qw(html_unescape md5_bytes md5_sum punycode_decode punycode_encode quote),
qw(secure_compare sha1_bytes sha1_sum slurp spurt squish trim unquote),
qw(url_escape url_unescape xml_escape xor_encode)
);

sub b64_decode { decode_base64(shift) }
Expand Down Expand Up @@ -126,14 +126,6 @@ sub html_unescape {
sub md5_bytes { md5(@_) }
sub md5_sum { md5_hex(@_) }

sub prompt {
local $| = 1;
print shift;
my $input = <STDIN>;
chomp $input;
return $input;
}

sub punycode_decode {
my $input = shift;
use integer;
Expand Down Expand Up @@ -533,14 +525,6 @@ Generate binary MD5 checksum for string.
Generate MD5 checksum for string.
=head2 C<prompt>
my $string = prompt 'Password: ';
Print string to C<STDOUT>, wait for user to type something and finish with an
C<ENTER> on C<STDIN>, then return the string typed in wihout the trailing
newline.
=head2 C<punycode_decode>
my $string = punycode_decode $punycode;
Expand Down
8 changes: 3 additions & 5 deletions lib/Mojolicious/Command/cpanify.pm
Expand Up @@ -3,7 +3,6 @@ use Mojo::Base 'Mojolicious::Command';

use File::Basename 'basename';
use Mojo::UserAgent;
use Mojo::Util 'prompt';

has description => "Upload distribution to CPAN.\n";
has usage => <<"EOF";
Expand All @@ -12,7 +11,7 @@ usage: $0 cpanify [OPTIONS] [FILE]
mojo cpanify -u sri -p secr3t Mojolicious-Plugin-MyPlugin-0.01.tar.gz
These options are available:
-p, --password <password> PAUSE password, defaults to a password prompt.
-p, --password <password> PAUSE password.
-u, --user <name> PAUSE username.
EOF

Expand All @@ -22,11 +21,10 @@ sub run {
# Options
$self->_options(
\@args,
'p|password=s' => \(my $password),
'u|user=s' => \(my $user = '')
'p|password=s' => \(my $password = ''),
'u|user=s' => \(my $user = '')
);
die $self->usage unless my $file = shift @args;
$password //= prompt 'Password: ';

# Upload
my $tx = Mojo::UserAgent->new->detect_proxy->post_form(
Expand Down
17 changes: 1 addition & 16 deletions t/mojo/bytestream.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 49;
use Test::More tests => 47;

use File::Spec::Functions qw(catfile splitdir);
use File::Temp 'tempdir';
Expand Down Expand Up @@ -141,21 +141,6 @@ b(1, 2, 3)->say;
*STDOUT = $stdout;
is $buffer, "test\n123\n", 'right output';

# prompt
my $input = "test123\n";
open my $in, '<', \$input;
my $output = '';
open my $out, '>', \$output;
my $stdin = *STDIN;
*STDIN = $in;
$stdout = *STDOUT;
*STDOUT = $out;
$stream = b('Password: ')->prompt;
*STDIN = $stdin;
*STDOUT = $stdout;
is $output, 'Password: ', 'right output';
is $stream, 'test123', 'right input';

# slurp
my $file = catfile splitdir($FindBin::Bin), qw(templates exception.mt);
$stream = b($file)->slurp;
Expand Down
23 changes: 4 additions & 19 deletions t/mojo/util.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 156;
use Test::More tests => 154;

use File::Spec::Functions qw(catfile splitdir);
use File::Temp 'tempdir';
Expand All @@ -11,9 +11,9 @@ use FindBin;
use Mojo::Util
qw(b64_decode b64_encode camelize class_to_file class_to_path decamelize),
qw(decode encode get_line hmac_md5_sum hmac_sha1_sum html_escape),
qw(html_unescape md5_bytes md5_sum prompt punycode_decode punycode_encode),
qw(quote squish trim unquote secure_compare sha1_bytes sha1_sum slurp),
qw(spurt url_escape url_unescape xml_escape xor_encode);
qw(html_unescape md5_bytes md5_sum punycode_decode punycode_encode quote),
qw(squish trim unquote secure_compare sha1_bytes sha1_sum slurp spurt),
qw(url_escape url_unescape xml_escape xor_encode);

# camelize
is camelize('foo_bar_baz'), 'FooBarBaz', 'right camelized result';
Expand Down Expand Up @@ -376,21 +376,6 @@ is xor_encode("\x10\x1d\x14\x14\x17\x58\x0f\x17\x0a\x14\x1c", 'x'),
is xor_encode('hello', '123456789'), "\x59\x57\x5f\x58\x5a", 'right result';
is xor_encode("\x59\x57\x5f\x58\x5a", '123456789'), 'hello', 'right result';

# prompt
my $input = "test123\n";
open my $in, '<', \$input;
my $output = '';
open my $out, '>', \$output;
my $stdin = *STDIN;
*STDIN = $in;
my $stdout = *STDOUT;
*STDOUT = $out;
my $string = prompt 'Password: ';
*STDIN = $stdin;
*STDOUT = $stdout;
is $output, 'Password: ', 'right output';
is $string, 'test123', 'right input';

# slurp
is slurp(catfile(splitdir($FindBin::Bin), qw(templates exception.mt))),
"test\n% die;\n123\n", 'right content';
Expand Down

0 comments on commit 4976aeb

Please sign in to comment.