Permalink
Browse files

Fixed utf8 query problem, fixed $hostname

  • Loading branch information...
Getty committed May 28, 2012
1 parent 4a6d74f commit ef5095b5c4098a7ab28ad7e881837ffe1cedcdbe
Showing with 24 additions and 6 deletions.
  1. +16 −0 lib/App/DuckPAN.pm
  2. +1 −1 lib/App/DuckPAN/Cmd/Query.pm
  3. +3 −1 lib/App/DuckPAN/Cmd/Server.pm
  4. +4 −4 lib/App/DuckPAN/Cmd/Setup.pm
View
@@ -18,6 +18,7 @@ use Class::Load ':all';
use Term::UI;
use Term::ReadLine;
use Carp;
+use Encode;
our $VERSION ||= '0.000';
@@ -66,6 +67,13 @@ has term => (
sub _build_term { Term::ReadLine->new('duckpan') }
+sub get_reply {
+ my ( $self, $prompt, %params ) = @_;
+ my $return = $self->term->get_reply( prompt => $prompt, %params );
+ Encode::_utf8_on($return);
+ return $return;
+}
+
has http => (
is => 'ro',
builder => '_build_http',
@@ -81,6 +89,14 @@ sub _build_http {
return $agent;
}
+has server_hostname => (
+ is => 'ro',
+ builder => 1,
+ lazy => 1,
+);
+
+sub _build_server_hostname { defined $ENV{APP_DUCKPAN_SERVER_HOSTNAME} ? $ENV{APP_DUCKPAN_SERVER_HOSTNAME} : 'duckduckgo.com' }
+
has config => (
is => 'ro',
builder => '_build_config',
@@ -14,7 +14,7 @@ sub run {
my @blocks = @{$self->app->ddg->get_blocks_from_current_dir(@args)};
print "\n(Empty query for ending test)\n";
- while (my $query = $self->app->term->get_reply( prompt => 'Query: ' ) ) {
+ while (my $query = $self->app->get_reply( 'Query: ' ) ) {
my $request = DDG::Request->new( query_raw => $query );
my $hit;
for (@blocks) {
@@ -28,7 +28,7 @@ sub run {
print "\n\nTrying to fetch current versions of the HTML from http://duckduckgo.com/\n\n";
- my $hostname = defined $ENV{APP_DUCKPAN_SERVER_HOSTNAME} ? $ENV{APP_DUCKPAN_SERVER_HOSTNAME} : 'duckduckgo.com';
+ my $hostname = $self->app->server_hostname;
my $fetch_page_root;
if ($fetch_page_root = get('http://'.$hostname.'/')) {
@@ -104,6 +104,8 @@ sub change_html {
my $root = HTML::TreeBuilder->new;
$root->parse($html);
+ my $hostname = $self->app->server_hostname;
+
my @a = $root->look_down(
"_tag", "a"
);
@@ -16,7 +16,7 @@ option user => (
default => sub { shift->get_user }
);
-sub get_user { shift->app->term->get_reply( prompt => 'What is your username on https://dukgo.com/ ? ' ) }
+sub get_user { shift->app->get_reply( 'What is your username on https://dukgo.com/ ? ' ) }
option pass => (
is => 'rw',
@@ -25,7 +25,7 @@ option pass => (
default => sub { shift->get_pass }
);
-sub get_pass { shift->app->term->get_reply( prompt => 'What is your password on https://dukgo.com/ ? ' ) }
+sub get_pass { shift->app->get_reply( 'What is your password on https://dukgo.com/ ? ' ) }
option name => (
is => 'rw',
@@ -34,7 +34,7 @@ option name => (
default => sub { shift->get_name }
);
-sub get_name { shift->app->term->get_reply( prompt => 'What is your name (real name not required) ? ' ) }
+sub get_name { shift->app->get_reply( 'What is your name (real name not required) ? ' ) }
option email => (
is => 'rw',
@@ -44,7 +44,7 @@ option email => (
default => sub { shift->get_email }
);
-sub get_email { shift->app->term->get_reply( prompt => 'What is your email (public in your release) ? ' ) }
+sub get_email { shift->app->get_reply( 'What is your email (public in your release) ? ' ) }
sub run {
my ( $self ) = @_;

0 comments on commit ef5095b

Please sign in to comment.