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);
41 # load configration data from yaml formatted file
42 # param => scalar string of filename
43 # ret => hash object of yaml data
47 my $yaml = YAML::Tiny->read($file);
50 warn "$0: '$file' $!\n";
57 # make Net::Twitter::Lite object and login
58 # param => hash object of configration
59 # ret => Net::Twitter::Lite object
63 my $bot = Net::Twitter::Lite->new(
64 consumer_key => $conf->{consumer_key},
65 consumer_secret => $conf->{consumer_secret},
68 $bot->access_token($conf->{access_token});
69 $bot->access_token_secret($conf->{access_token_secret});
75 # output error message at eval error
77 use Scalar::Util qw(blessed);
79 if (blessed $@ && $@->isa('Net::Twitter::Lite::Error')) {
81 if ($@->twitter_error) {
82 my %twitter_error = %{$@->twitter_error};
84 $twitter_error{"$_ => "} = $twitter_error{$_} . "\n";
85 delete $twitter_error{$_}
86 } keys %twitter_error;
87 warn join("", %twitter_error);