| 1 | package Horris::Connection::Plugin::Twitter; | ||||||||||
| 2 | # ABSTRACT: Evaluate Plugin on Horris | ||||||||||
| 3 | |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use HTTP::Request; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use HTTP::Response; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | extends 'Horris::Connection::Plugin'; | |||||||||
| 10 | 1 | with 'MooseX::Role::Pluggable::Plugin'; | |||||||||
| 11 | |||||||||||
| 12 | 0 | ▶ | sub irc_privmsg { | ||||||||
|
Subroutine
irc_privmsg: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 13 | 0 | my ($self, $message) = @_; | |||||||||
| 14 | 0 | my $msg = $self->_parse_status($message); | |||||||||
| 15 | |||||||||||
| 16 | 0 | ▶ | return $self->pass unless defined $msg; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | |||||||||||
| 18 | 0 | for my $m (split(/\n/, $msg)) { | |||||||||
| 19 | 0 | $self->connection->irc_privmsg({ | |||||||||
| 20 | channel => $message->channel, | ||||||||||
| 21 | message => $m | ||||||||||
| 22 | }); | ||||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 0 | return $self->done; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub _parse_status { | ||||||||
|
Subroutine
_parse_status: not called CC=6 SCAR=37.4
| |||||||||||
| 29 | 0 | my ($self, $message) = @_; | |||||||||
| 30 | 0 | my $raw = $message->message; | |||||||||
| 31 | 0 | $raw =~ s/#!\///; | |||||||||
| 32 | 0 | my $url; | |||||||||
| 33 | 0 | ▶ | unless (($url) = $raw =~ m{(https?://(:?.*)twitter\.com/(:?[^/]+)/st\w+/[0-9]+)}) { # status, statuses | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | return undef; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | print "recv Twitter URI\n" if $Horris::DEBUG; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | |||||||||||
| 39 | 0 | my ($msg, $nick); | |||||||||
| 40 | 0 | my $request = HTTP::Request->new( GET => $url ); | |||||||||
| 41 | 0 | my $ua = LWP::UserAgent->new; | |||||||||
| 42 | 0 | my $response = $ua->request($request); | |||||||||
| 43 | 0 | ▶ | if ($response->is_success) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | ▶ | if ($url =~ /mobile\./i) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | 0 | ($msg) = $response->content =~ m{<span class="status">(.*)</span>}m; | |||||||||
| 46 | 0 | ($nick) = $url =~ m{(\w+)/status}; | |||||||||
| 47 | 0 | $msg =~ s{<[^>]*>}{}g; | |||||||||
| 48 | 0 | $msg = $nick . ': ' . $msg; | |||||||||
| 49 | } else { | ||||||||||
| 50 | 0 | ($nick) = $response->content =~ m{<title id="page_title">Twitter / ([^:]*)}; | |||||||||
| 51 | 0 | ($msg) = $response->content =~ m{<meta content="([^"]*)" name="description" />}m; | |||||||||
| 52 | 0 | $msg = $nick . ': ' . $msg; | |||||||||
| 53 | } | ||||||||||
| 54 | } else { | ||||||||||
| 55 | 0 | ▶ | $msg = $response->status_line unless $response->is_success; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | } | ||||||||||
| 57 | 0 | return $msg; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 61 | |||||||||||
| 62 | 1 | 1; | |||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||