Simple/Twitter.pm

filter: Statementstmt 59.5% 25 / 42 Branchbran 10.0% 1 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 85.7% 6 / 7 Podpod 100% 2 / 2 totaltotal 51.4% 36 / 70 CC 8 SCAR 25.2
CC
8
Cov
48%
log
30.0
new
4.9
BEGIN
1.0
CRAP 12.5
↑ Summary Simple/HTTP.pm »
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
BranchTrueFalseTotal
if ($app->{'oauth_file'}) { } 0 5 5
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'}
l!l&&r!l&&!r
005
$app->{"user"} or $ENV{"SUDO_USER"}
l!l&&r!l&&!r
005
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'}
ABCresult
1XX1
01X1
0011
0000
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
BranchTrueFalseTotal
unless $self->{"do_twitter"} 0 0 0
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
BranchTrueFalseTotal
if ($self->{"oauth_file"}->stat->mode & 4095) != 384 0 0 0
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
BranchTrueFalseTotal
defined __PACKAGE__->VERSION ? : 0 0 0
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
BranchTrueFalseTotal
unless $result->{"text"} eq $logentry 0 0 0
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__
↑ Summary Simple/HTTP.pm »