Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed utf8 query problem, fixed $hostname
  • Loading branch information
Getty committed May 28, 2012
1 parent 4a6d74f commit ef5095b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
16 changes: 16 additions & 0 deletions lib/App/DuckPAN.pm
Expand Up @@ -18,6 +18,7 @@ use Class::Load ':all';
use Term::UI;
use Term::ReadLine;
use Carp;
use Encode;

our $VERSION ||= '0.000';

Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion lib/App/DuckPAN/Cmd/Query.pm
Expand Up @@ -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) {
Expand Down
4 changes: 3 additions & 1 deletion lib/App/DuckPAN/Cmd/Server.pm
Expand Up @@ -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.'/')) {
Expand Down Expand Up @@ -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"
);
Expand Down
8 changes: 4 additions & 4 deletions lib/App/DuckPAN/Cmd/Setup.pm
Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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 ) = @_;
Expand Down

0 comments on commit ef5095b

Please sign in to comment.