| 1 | package POE::Component::IRC::Plugin::WWW::Vim::Tips; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 1 | ▶ | use 5.008_005; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 1 | our $VERSION = '0.14'; | |||||||||||||
| 8 | |||||||||||||||
| 9 | 1 | ▶ | use POE::Component::IRC::Plugin qw( :ALL ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 1 | ▶ | use HTML::TreeBuilder::XPath; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 1 | ▶ | use LWP::Simple qw(get); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 1 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 14 | 1 | my $package = shift; | |||||||||||||
| 15 | 1 | return bless {}, $package; | |||||||||||||
| 16 | } | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 0 | ▶ | sub PCI_register { | ||||||||||||
|
Subroutine
PCI_register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 19 | 0 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||
| 20 | |||||||||||||||
| 21 | 0 | $irc->plugin_register($self, 'SERVER', qw(public)); | |||||||||||||
| 22 | 0 | return 1; | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | |||||||||||||||
| 25 | # This is method is mandatory but we don't actually have anything to do. | ||||||||||||||
| 26 | 0 | ▶ | sub PCI_unregister { | ||||||||||||
|
Subroutine
PCI_unregister: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 27 | 0 | return 1; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 0 | ▶ | sub S_public { | ||||||||||||
|
Subroutine
S_public: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||
| 31 | 0 | my ($self, $irc) = splice @_, 0, 2; | |||||||||||||
| 32 | |||||||||||||||
| 33 | # Parameters are passed as scalar-refs including arrayrefs. | ||||||||||||||
| 34 | 0 | my $nick = (split /!/, ${$_[0]})[0]; | |||||||||||||
| 35 | 0 | my $channel = ${$_[1]}->[0]; | |||||||||||||
| 36 | 0 | my $msg = ${$_[2]}; | |||||||||||||
| 37 | |||||||||||||||
| 38 | 0 | ▶ | my $reply = | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 39 | ($msg =~ /^!vimtips?\b/i) ? $self->_get_vim_tip | ||||||||||||||
| 40 | : ($msg =~ /^!emacstips?\b/i) ? 'use Vim' | ||||||||||||||
| 41 | : ''; | ||||||||||||||
| 42 | 0 | ▶ | if ($reply) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | 0 | $irc->yield(privmsg => $channel => "$nick: $reply"); | |||||||||||||
| 44 | 0 | return PCI_EAT_PLUGIN; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | |||||||||||||||
| 47 | # Default action is to allow other plugins to process it. | ||||||||||||||
| 48 | 0 | return PCI_EAT_NONE; | |||||||||||||
| 49 | } | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 0 | ▶ | sub _get_vim_tip { | ||||||||||||
|
Subroutine
_get_vim_tip: not called CC=1 SCAR=6.9
| |||||||||||||||
| 52 | 0 | my $content = get('http://twitter.com/vimtips'); | |||||||||||||
| 53 | 0 | my $tree = HTML::TreeBuilder::XPath->new_from_content($content); | |||||||||||||
| 54 | 0 | my @tips = grep { s/\x{a0}/ /g; s/^\s*|\s*$//g; 1 } # | |||||||||||||
| 55 | $tree->findvalues( | ||||||||||||||
| 56 | './/div[@class=~/\bprofile-stream\b/] | ||||||||||||||
| 57 | //p[@class=~/\btweet-text\b/]' | ||||||||||||||
| 58 | ); | ||||||||||||||
| 59 | 0 | return $tips[rand @tips]; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 1 | 1; | |||||||||||||
| 63 | |||||||||||||||
| 64 | __END__ | ||||||||||||||