| 1 | package App::Sysadmin::Log::Simple::Twitter; | ||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use autodie qw(:file :filesys); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use Config::General qw(ParseConfig); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use Path::Tiny; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | # ABSTRACT: a Twitter-logger for App::Sysadmin::Log::Simple | ||||||||||||||||||||||||||||||||||
| 9 | 6 | our $VERSION = '0.009'; # VERSION | |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||
| 12 | 5 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=16.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 13 | 5 | my $class = shift; | |||||||||||||||||||||||||||||||||
| 14 | 5 | my %opts = @_; | |||||||||||||||||||||||||||||||||
| 15 | 5 | my $app = $opts{app}; | |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 5 | my $oauth_file; | |||||||||||||||||||||||||||||||||
| 18 | 5 | ▶ | if ($app->{oauth_file}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 19 | 0 | $oauth_file = $app->{oauth_file}; | |||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||
| 21 | else { | ||||||||||||||||||||||||||||||||||
| 22 | 5 | require File::HomeDir; | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||
| 24 | my $HOME = File::HomeDir->users_home( | ||||||||||||||||||||||||||||||||||
| 25 | $app->{user} || $ENV{SUDO_USER} || $ENV{USER} | ||||||||||||||||||||||||||||||||||
| 26 | 5 | ▶ | ); | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$app->{'user'} || $ENV{'SUDO_USER'} || $ENV{'USER'}
$app->{"user"} or $ENV{"SUDO_USER"}
MC/DC0%0/3
$app->{'user'} || $ENV{'SUDO_USER'} || $ENV{'USER'}
$app->{"user"}
$ENV{"SUDO_USER"}
$ENV{'USER'}
Truth table25%1/4
A or B || C
A= $app->{"user"}B= $ENV{"SUDO_USER"}C= $ENV{'USER'}
| |||||||||||||||||||||||||||||||||||
| 27 | 5 | $oauth_file = path($HOME, '.sysadmin-log-twitter-oauth'); | |||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | return bless { | ||||||||||||||||||||||||||||||||||
| 31 | oauth_file => $oauth_file, | ||||||||||||||||||||||||||||||||||
| 32 | do_twitter => $app->{do_twitter}, | ||||||||||||||||||||||||||||||||||
| 33 | 0 | }, $class; | |||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | sub log { | ||||||||||||||||||||||||||||||||
|
Subroutine
log: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 38 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 39 | 0 | my $logentry = shift; | |||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | return unless $self->{do_twitter}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||
| 43 | 0 | require Net::Twitter::Lite::WithAPIv1_1; | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | warn "You should do: chmod 600 $self->{oauth_file}\n" | ||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ($self->{oauth_file}->stat->mode & 07777) != 0600; ## no critic (ValuesAndExpressions::ProhibitLeadingZeros) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 47 | 0 | my $conf = Config::General->new($self->{oauth_file}); | |||||||||||||||||||||||||||||||||
| 48 | 0 | my %oauth = $conf->getall(); | |||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $ua = __PACKAGE__ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 51 | . '/' . (defined __PACKAGE__->VERSION ? __PACKAGE__->VERSION : 'dev'); | ||||||||||||||||||||||||||||||||||
| 52 | 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 | 0 | 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 | ▶ | die 'Something went wrong' unless $result->{text} eq $logentry; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||
| 66 | my $url = 'https://twitter.com/' | ||||||||||||||||||||||||||||||||||
| 67 | . $result->{user}->{screen_name} | ||||||||||||||||||||||||||||||||||
| 68 | 0 | . '/status/' . $result->{id_str}; | |||||||||||||||||||||||||||||||||
| 69 | 0 | return "Posted to Twitter: $url"; | |||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 6 | 1; | |||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||||||||