From a5b6bf1b18c7adf5e32cc0e020e76b26272902af Mon Sep 17 00:00:00 2001 From: Ken-ichi Mito Date: Fri, 21 Jun 2013 15:38:04 +0900 Subject: [PATCH] fix evalrescue fuction * dereference Net::Twitter::Lite::Error->twitter_error object correctly * use Data::Dumper for unknown structure --- Dev/twitter/dump_timeline.pl | 18 ++++++++++++------ Dev/twitter/show_status.pl | 18 ++++++++++++------ Dev/twitter/twitterbot.pl | 18 ++++++++++++------ Dev/twitter/update_timeline.pl | 18 ++++++++++++------ 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Dev/twitter/dump_timeline.pl b/Dev/twitter/dump_timeline.pl index 48a1412..484a228 100755 --- a/Dev/twitter/dump_timeline.pl +++ b/Dev/twitter/dump_timeline.pl @@ -159,12 +159,18 @@ sub evalrescue { if (blessed $@ && $@->isa('Net::Twitter::Lite::Error')) { warn $@->error; if ($@->twitter_error) { - my %twitter_error = %{$@->twitter_error}; - map { - $twitter_error{"$_ => "} = $twitter_error{$_} . "\n"; - delete $twitter_error{$_} - } keys %twitter_error; - warn join("", %twitter_error); + my $twitter_error = $@->twitter_error; + if (defined $twitter_error->{errors}) { + foreach my $error (@{$twitter_error->{errors}}) { + warn "code => " , $error->{code}, "\n"; + warn "message => ", $error->{message}, "\n"; + } + } + else { + # unknown HASH structure + use Data::Dumper; + warn Dumper $twitter_error; + } } } else { diff --git a/Dev/twitter/show_status.pl b/Dev/twitter/show_status.pl index ee45ace..5c22a92 100755 --- a/Dev/twitter/show_status.pl +++ b/Dev/twitter/show_status.pl @@ -57,12 +57,18 @@ sub evalrescue { if (blessed $@ && $@->isa('Net::Twitter::Lite::Error')) { warn $@->error; if ($@->twitter_error) { - my %twitter_error = %{$@->twitter_error}; - map { - $twitter_error{"$_ => "} = $twitter_error{$_} . "\n"; - delete $twitter_error{$_} - } keys %twitter_error; - warn join("", %twitter_error); + my $twitter_error = $@->twitter_error; + if (defined $twitter_error->{errors}) { + foreach my $error (@{$twitter_error->{errors}}) { + warn "code => " , $error->{code}, "\n"; + warn "message => ", $error->{message}, "\n"; + } + } + else { + # unknown HASH structure + use Data::Dumper; + warn Dumper $twitter_error; + } } } else { diff --git a/Dev/twitter/twitterbot.pl b/Dev/twitter/twitterbot.pl index bb7baa0..7eeed96 100755 --- a/Dev/twitter/twitterbot.pl +++ b/Dev/twitter/twitterbot.pl @@ -301,12 +301,18 @@ sub evalrescue { if (blessed $@ && $@->isa('Net::Twitter::Lite::Error')) { warn $@->error; if ($@->twitter_error) { - my %twitter_error = %{$@->twitter_error}; - map { - $twitter_error{"$_ => "} = $twitter_error{$_} . "\n"; - delete $twitter_error{$_} - } keys %twitter_error; - warn join("", %twitter_error); + my $twitter_error = $@->twitter_error; + if (defined $twitter_error->{errors}) { + foreach my $error (@{$twitter_error->{errors}}) { + warn "code => " , $error->{code}, "\n"; + warn "message => ", $error->{message}, "\n"; + } + } + else { + # unknown HASH structure + use Data::Dumper; + warn Dumper $twitter_error; + } } } else { diff --git a/Dev/twitter/update_timeline.pl b/Dev/twitter/update_timeline.pl index 633db89..02a6433 100755 --- a/Dev/twitter/update_timeline.pl +++ b/Dev/twitter/update_timeline.pl @@ -111,12 +111,18 @@ sub evalrescue { if (blessed $@ && $@->isa('Net::Twitter::Lite::Error')) { warn $@->error; if ($@->twitter_error) { - my %twitter_error = %{$@->twitter_error}; - map { - $twitter_error{"$_ => "} = $twitter_error{$_} . "\n"; - delete $twitter_error{$_} - } keys %twitter_error; - warn join("", %twitter_error); + my $twitter_error = $@->twitter_error; + if (defined $twitter_error->{errors}) { + foreach my $error (@{$twitter_error->{errors}}) { + warn "code => " , $error->{code}, "\n"; + warn "message => ", $error->{message}, "\n"; + } + } + else { + # unknown HASH structure + use Data::Dumper; + warn Dumper $twitter_error; + } } } else { -- 1.7.9.5