8 # When Net::Twitter::Lite encounters a Twitter API error or a network error,
9 # it throws a Net::Twitter::Lite::Error object.
10 # You can catch and process these exceptions by using eval blocks and testing $@
11 ## from http://search.cpan.org/perldoc?Net::Twitter::Lite#ERROR_HANDLING
12 use Net::Twitter::Lite;
16 my $conf = loadconf("$Bin/config.yml");
17 if (! defined $conf) {
18 die "$0: cannot parse config file.\n";
21 my $bot = login($conf);
22 if (! $bot->authorized) {
23 die "$0: this client is not yet authorized.\n";
28 foreach my $id (@ARGV) {
29 my $res = $bot->show_status($id);
31 foreach my $line (split /\n/, Dumper $res) {
32 if ($line =~ /undef/) { next; }
33 unless ($line =~ / => {/
54 # load configration data from yaml formatted file
55 # param => scalar string of filename
56 # ret => hash object of yaml data
60 my $yaml = YAML::Tiny->read($file);
63 warn "$0: '$file' $!\n";
70 # make Net::Twitter::Lite object and login
71 # param => hash object of configration
72 # ret => Net::Twitter::Lite object
76 my $bot = Net::Twitter::Lite->new(
77 consumer_key => $conf->{consumer_key},
78 consumer_secret => $conf->{consumer_secret},
81 $bot->access_token($conf->{access_token});
82 $bot->access_token_secret($conf->{access_token_secret});
88 # output error message at eval error
90 use Scalar::Util qw(blessed);
92 if (blessed $@ && $@->isa('Net::Twitter::Lite::Error')) {
94 if ($@->twitter_error) {
95 my %twitter_error = %{$@->twitter_error};
97 $twitter_error{"$_ => "} = $twitter_error{$_} . "\n";
98 delete $twitter_error{$_}
99 } keys %twitter_error;
100 warn join("", %twitter_error);