Permalink
Browse files

better error handling with LWP::UserAgent instead of LWP::Simple

  • Loading branch information...
1 parent 5b2aaf4 commit 2aa137c5c8c35f56fe5c500e7fadad7dca229d6b @tokuhirom tokuhirom committed Feb 28, 2010
Showing with 8 additions and 2 deletions.
  1. +8 −2 lib/App/NoPAN.pm
View
10 lib/App/NoPAN.pm
@@ -27,9 +27,13 @@ __PACKAGE__->mk_accessors(keys %Defaults);
sub new {
my ($klass, %opts) = @_;
+ my $ua = LWP::UserAgent->new();
+ $ua->agent("nopan");
+ $ua->env_proxy;
bless {
%Defaults,
%opts,
+ ua => $ua,
}, $klass;
}
@@ -97,8 +101,10 @@ sub fetch_all {
sub files_from_dir {
my ($self, $url) = @_;
- my $body = LWP::Simple::get($url)
- or die "failed to fetch URL:$url";
+ my $res = $self->{ua}->get($url);
+ $res->is_success
+ or die "failed to fetch URL:$url, @{[ $res->status_line ]}";
+ my $body = $res->content;
return grep {
$_ !~ m{^(\.{1,2}|)$},
} map {

0 comments on commit 2aa137c

Please sign in to comment.