| 1 | package App::Twirc; | ||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $App::Twirc::VERSION = '0.20'; | |||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Config::Any; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use POE qw/Loop::AnyEvent Wheel::ReadWrite/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use AnyEvent::Twitter; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use POE::Component::Server::Twirc; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Proc::Daemon; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Path::Class::File; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Log::Log4perl qw/:easy/; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | 1 | with 'MooseX::Getopt', | |||||||||||||||||||||||||||||||||||||
| 13 | 'MooseX::Log::Log4perl::Easy'; | ||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||
| 15 | 1 | has configfile => ( | |||||||||||||||||||||||||||||||||||||
| 16 | metaclass => 'Getopt', | ||||||||||||||||||||||||||||||||||||||
| 17 | cmd_aliases => 'c', | ||||||||||||||||||||||||||||||||||||||
| 18 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 20 | documentation => 'configration file name', | ||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||
| 23 | 1 | has background => ( | |||||||||||||||||||||||||||||||||||||
| 24 | metaclass => 'Getopt', | ||||||||||||||||||||||||||||||||||||||
| 25 | cmd_aliases => 'b', | ||||||||||||||||||||||||||||||||||||||
| 26 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||
| 27 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 28 | documentation => 'run as daemon', | ||||||||||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | 1 | has authenticate => ( | |||||||||||||||||||||||||||||||||||||
| 32 | metaclass => 'Getopt', | ||||||||||||||||||||||||||||||||||||||
| 33 | cmd_aliases => [qw/a auth/], | ||||||||||||||||||||||||||||||||||||||
| 34 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 36 | default => 0, | ||||||||||||||||||||||||||||||||||||||
| 37 | documentation => 'force Twitter authentication', | ||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||
| 40 | 1 | has state_file => ( | |||||||||||||||||||||||||||||||||||||
| 41 | metaclass => 'Getopt', | ||||||||||||||||||||||||||||||||||||||
| 42 | cmd_aliases => 's', | ||||||||||||||||||||||||||||||||||||||
| 43 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||
| 44 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 45 | predicate => 'has_state_file', | ||||||||||||||||||||||||||||||||||||||
| 46 | documentation => 'state file name', | ||||||||||||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||
| 49 | 1 | has debug => ( | |||||||||||||||||||||||||||||||||||||
| 50 | metaclass => 'Getopt', | ||||||||||||||||||||||||||||||||||||||
| 51 | cmd_aliases => 'd', | ||||||||||||||||||||||||||||||||||||||
| 52 | isa => 'Bool', | ||||||||||||||||||||||||||||||||||||||
| 53 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 54 | default => 0, | ||||||||||||||||||||||||||||||||||||||
| 55 | documentation => 'set logging level to DEBUG', | ||||||||||||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub run { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
run: not called CC=14 SCAR=53.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||
| 61 | 0 | my $config; | |||||||||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ( my $file = $self->configfile ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $config = Config::Any->load_files({ files => [ $file ], use_ext => 1 }); | |||||||||||||||||||||||||||||||||||||
| 64 | 0 | $config = $config->[0]{$file}; | |||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||
| 67 | # override/provide config options from the commandline | ||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $$config{state_file} = $self->state_file if $self->has_state_file; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $$config{log_level} = 'DEBUG' if $self->debug; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||
| 71 | Log::Log4perl->easy_init({ | ||||||||||||||||||||||||||||||||||||||
| 72 | layout => '%d{HH:mm:ss} [%p] %m%n', | ||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | level => $$config{log_level} && eval "\$$$config{log_level}" || $WARN, | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$config->{'log_level'} && eval "\$$config->{'log_level'}" || $App::Twirc::WARN
$config->{"log_level"} and eval qq[\$$config->{"log_level"}]
MC/DC0%0/3
$config->{'log_level'} && eval "\$$config->{'log_level'}" || $App::Twirc::WARN
$config->{"log_level"}
eval qq[\$$config->{"log_level"}]
$App::Twirc::WARN
Truth table0%0/5
A and B || C
A= $config->{"log_level"}B= eval qq[\$$config->{"log_level"}]C= $App::Twirc::WARN
| |||||||||||||||||||||||||||||||||||||||
| 74 | }); | ||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||
| 76 | # Make sure state_file is absolute before we background (which does a cd /). | ||||||||||||||||||||||||||||||||||||||
| 77 | $$config{state_file} = Path::Class::File->new($config->{state_file})->absolute->stringify | ||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if $$config{state_file}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||
| 80 | my $state = $$config{state_file} && -r $$config{state_file} | ||||||||||||||||||||||||||||||||||||||
| 81 | ? POE::Component::Server::Twirc::State->load($$config{state_file}) | ||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | : POE::Component::Server::Twirc::State->new; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$config->{"state_file"} and -r $config->{"state_file"}
MC/DC0%0/2
$config->{"state_file"} and -r $config->{"state_file"}
$config->{"state_file"}
-r $config->{"state_file"}
Truth table0%0/3
A and B
A= $config->{"state_file"}B= -r $config->{"state_file"}
| |||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $self->oauth_handshake($state, $$config{sate_file}) if $self->authenticate || !$state->access_token; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->authenticate or not $state->access_token
MC/DC0%0/2
$self->authenticate or not $state->access_token
$self->authenticate
not $state->access_token
Truth table0%0/3
A or not(B)
A= $self->authenticateB= not $state->access_token
| |||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | if ( $self->background ) { | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 87 | 0 | Proc::Daemon::Init; | |||||||||||||||||||||||||||||||||||||
| 88 | 0 | POE::Kernel->has_forked; | |||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||
| 90 | else { | ||||||||||||||||||||||||||||||||||||||
| 91 | 0 | eval 'use POE qw(Component::TSTP)'; | |||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | die "$@\n" if $@; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $config->{plugins} = $self->_init_plugins($config); | |||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | POE::Component::Server::Twirc->new(%{$config || {}}, state => $state); | ||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$config || {}
MC/DC0%0/1
$config || {}
$config
Truth table0%0/2
A
A= $config
| |||||||||||||||||||||||||||||||||||||||
| 97 | 0 | POE::Kernel->run; | |||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub oauth_handshake { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
oauth_handshake: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my ( $self, $state, $state_file ) = @_; | |||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my %consumer = POE::Component::Server::Twirc->_twitter_auth; | |||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my ( $wheel, $oauth ); | |||||||||||||||||||||||||||||||||||||
| 106 | POE::Session->create( | ||||||||||||||||||||||||||||||||||||||
| 107 | inline_states => { | ||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | _start => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $cb = $_[SESSION]->postback('get_pin'); | |||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $w; $w = AnyEvent::Twitter->get_request_token( | |||||||||||||||||||||||||||||||||||||
| 111 | %consumer, | ||||||||||||||||||||||||||||||||||||||
| 112 | callback_url => 'oob', | ||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | cb => sub { $cb->(@_); undef $w } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ); | |||||||||||||||||||||||||||||||||||||
| 115 | }, | ||||||||||||||||||||||||||||||||||||||
| 116 | 0 | ▶ | get_pin => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my ( $url, $r, $body, $header ) = @{ $_[ARG1] }; | |||||||||||||||||||||||||||||||||||||
| 118 | 0 | $oauth = $r; | |||||||||||||||||||||||||||||||||||||
| 119 | 0 | $wheel = POE::Wheel::ReadWrite->new( | |||||||||||||||||||||||||||||||||||||
| 120 | InputHandle => \*STDIN, | ||||||||||||||||||||||||||||||||||||||
| 121 | OutputHandle => \*STDOUT, | ||||||||||||||||||||||||||||||||||||||
| 122 | InputEvent => 'got_pin' | ||||||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||||||
| 124 | 0 | print "Authorize twirc at $url\nThen, enter the PIN# provided: "; | |||||||||||||||||||||||||||||||||||||
| 125 | }, | ||||||||||||||||||||||||||||||||||||||
| 126 | 0 | ▶ | got_pin => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 127 | 0 | undef $wheel; | |||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $pin = $_[ARG0]; | |||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $cb = $_[SESSION]->postback('got_access_token'); | |||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $w; $w = AnyEvent::Twitter->get_access_token( | |||||||||||||||||||||||||||||||||||||
| 131 | %consumer, | ||||||||||||||||||||||||||||||||||||||
| 132 | oauth_token => $$oauth{oauth_token}, | ||||||||||||||||||||||||||||||||||||||
| 133 | oauth_token_secret => $$oauth{oauth_token_secret}, | ||||||||||||||||||||||||||||||||||||||
| 134 | oauth_verifier => $pin, | ||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | cb => sub { $cb->(@_); undef $w } | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ); | |||||||||||||||||||||||||||||||||||||
| 137 | }, | ||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | got_access_token => sub { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my ( $r, $body, $header ) = @{ $_[ARG1] }; | |||||||||||||||||||||||||||||||||||||
| 140 | 0 | $state->access_token($$r{oauth_token}); | |||||||||||||||||||||||||||||||||||||
| 141 | 0 | $state->access_token_secret($$r{oauth_token_secret}); | |||||||||||||||||||||||||||||||||||||
| 142 | 0 | ▶ | $state->store($state_file) if $state_file; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 143 | }, | ||||||||||||||||||||||||||||||||||||||
| 144 | }, | ||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ); | |||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||
| 147 | 0 | POE::Kernel->run; | |||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub _init_plugins { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
_init_plugins: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||
| 151 | 0 | my ($self, $config) = @_; | |||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $plugins = delete $config->{plugins}; | |||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my @plugins; | |||||||||||||||||||||||||||||||||||||
| 156 | 0 | for my $plugin ( @$plugins ) { | |||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | my ($class, $options) = ref $plugin ? %$plugin : ($plugin, {}); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | $class = "App::Twirc::Plugin::$class" unless $class =~ s/^\+//; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||
| 160 | 0 | eval "use $class"; | |||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||
| 163 | 0 | push @plugins, $class->new($options); | |||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||
| 165 | 0 | return \@plugins; | |||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||
| 170 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||
| 172 | 1 | 1; | |||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||
| 174 | __END__ | ||||||||||||||||||||||||||||||||||||||