| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package App::Sysadmin::Log::Simple::Twitter; |
|
2
|
5
|
|
|
5
|
|
47091
|
use strict; |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
183
|
|
|
3
|
5
|
|
|
5
|
|
25
|
use warnings; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
160
|
|
|
4
|
5
|
|
|
5
|
|
7107
|
use autodie qw(:file :filesys); |
|
|
5
|
|
|
|
|
24146
|
|
|
|
5
|
|
|
|
|
41
|
|
|
5
|
5
|
|
|
5
|
|
19216
|
use Config::General qw(ParseConfig); |
|
|
5
|
|
|
|
|
101359
|
|
|
|
5
|
|
|
|
|
502
|
|
|
6
|
5
|
|
|
5
|
|
1341
|
use Path::Tiny; |
|
|
5
|
|
|
|
|
15481
|
|
|
|
5
|
|
|
|
|
2940
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: a Twitter-logger for App::Sysadmin::Log::Simple |
|
9
|
|
|
|
|
|
|
our $VERSION = '0.009'; # VERSION |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
6
|
|
|
6
|
1
|
1351
|
my $class = shift; |
|
14
|
6
|
|
|
|
|
15
|
my %opts = @_; |
|
15
|
6
|
|
|
|
|
17
|
my $app = $opts{app}; |
|
16
|
|
|
|
|
|
|
|
|
17
|
6
|
|
|
|
|
11
|
my $oauth_file; |
|
18
|
6
|
50
|
|
|
|
25
|
if ($app->{oauth_file}) { |
|
19
|
0
|
|
|
|
|
0
|
$oauth_file = $app->{oauth_file}; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
|
|
|
|
|
|
else { |
|
22
|
6
|
|
|
|
|
7450
|
require File::HomeDir; |
|
23
|
|
|
|
|
|
|
|
|
24
|
6
|
|
33
|
|
|
35717
|
my $HOME = File::HomeDir->users_home( |
|
25
|
|
|
|
|
|
|
$app->{user} || $ENV{SUDO_USER} || $ENV{USER} |
|
26
|
|
|
|
|
|
|
); |
|
27
|
6
|
|
|
|
|
4965
|
$oauth_file = path($HOME, '.sysadmin-log-twitter-oauth'); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return bless { |
|
31
|
|
|
|
|
|
|
oauth_file => $oauth_file, |
|
32
|
|
|
|
|
|
|
do_twitter => $app->{do_twitter}, |
|
33
|
|
|
|
|
|
|
}, $class; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub log { |
|
38
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
39
|
0
|
|
|
|
|
|
my $logentry = shift; |
|
40
|
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
return unless $self->{do_twitter}; |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
require Net::Twitter::Lite::WithAPIv1_1; |
|
44
|
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
warn "You should do: chmod 600 $self->{oauth_file}\n" |
|
46
|
|
|
|
|
|
|
if ($self->{oauth_file}->stat->mode & 07777) != 0600; ## no critic (ValuesAndExpressions::ProhibitLeadingZeros) |
|
47
|
0
|
|
|
|
|
|
my $conf = Config::General->new($self->{oauth_file}); |
|
48
|
0
|
|
|
|
|
|
my %oauth = $conf->getall(); |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
my $ua = __PACKAGE__ |
|
51
|
|
|
|
|
|
|
. '/' . (defined __PACKAGE__->VERSION ? __PACKAGE__->VERSION : 'dev'); |
|
52
|
0
|
|
|
|
|
|
my $t = Net::Twitter::Lite::WithAPIv1_1->new( |
|
53
|
|
|
|
|
|
|
consumer_key => $oauth{consumer_key}, |
|
54
|
|
|
|
|
|
|
consumer_secret => $oauth{consumer_secret}, |
|
55
|
|
|
|
|
|
|
access_token => $oauth{oauth_token}, |
|
56
|
|
|
|
|
|
|
access_token_secret => $oauth{oauth_token_secret}, |
|
57
|
|
|
|
|
|
|
ssl => 1, |
|
58
|
|
|
|
|
|
|
useragent => $ua, |
|
59
|
|
|
|
|
|
|
); |
|
60
|
0
|
|
|
|
|
|
$t->access_token($oauth{oauth_token}); |
|
61
|
0
|
|
|
|
|
|
$t->access_token_secret($oauth{oauth_token_secret}); |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $result = $t->update($logentry); |
|
64
|
0
|
0
|
|
|
|
|
die 'Something went wrong' unless $result->{text} eq $logentry; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $url = 'https://twitter.com/' |
|
67
|
|
|
|
|
|
|
. $result->{user}->{screen_name} |
|
68
|
|
|
|
|
|
|
. '/status/' . $result->{id_str}; |
|
69
|
0
|
|
|
|
|
|
return "Posted to Twitter: $url"; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |