From: Ken-ichi Mito <mitty@mitty.jp>
Date: Fri, 21 Jun 2013 06:38:04 +0000 (+0900)
Subject: fix evalrescue fuction
X-Git-Url: http://lab.mitty.jp/git/?a=commitdiff_plain;h=a5b6bf1b18c7adf5e32cc0e020e76b26272902af;p=lab.git

fix evalrescue fuction

 * dereference Net::Twitter::Lite::Error->twitter_error object correctly
 * use Data::Dumper for unknown structure
---

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 {