fix evalrescue fuction
authorKen-ichi Mito <mitty@mitty.jp>
Fri, 21 Jun 2013 06:38:04 +0000 (15:38 +0900)
committerKen-ichi Mito <mitty@mitty.jp>
Fri, 21 Jun 2013 06:38:04 +0000 (15:38 +0900)
 * dereference Net::Twitter::Lite::Error->twitter_error object correctly
 * use Data::Dumper for unknown structure

Dev/twitter/dump_timeline.pl
Dev/twitter/show_status.pl
Dev/twitter/twitterbot.pl
Dev/twitter/update_timeline.pl

index 48a1412..484a228 100755 (executable)
@@ -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 {
index ee45ace..5c22a92 100755 (executable)
@@ -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 {
index bb7baa0..7eeed96 100755 (executable)
@@ -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 {
index 633db89..02a6433 100755 (executable)
@@ -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 {