line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package POE::Component::IRC::Plugin::WWW::Vim::Tips; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23301
|
use 5.008_005; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
60
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.14'; |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
949
|
use POE::Component::IRC::Plugin qw( :ALL ); |
|
1
|
|
|
|
|
562
|
|
|
1
|
|
|
|
|
166
|
|
10
|
1
|
|
|
1
|
|
980
|
use HTML::TreeBuilder::XPath; |
|
1
|
|
|
|
|
91931
|
|
|
1
|
|
|
|
|
13
|
|
11
|
1
|
|
|
1
|
|
1183
|
use LWP::Simple qw(get); |
|
1
|
|
|
|
|
2633217
|
|
|
1
|
|
|
|
|
14
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
1
|
|
|
1
|
0
|
1190
|
my $package = shift; |
15
|
1
|
|
|
|
|
7
|
return bless {}, $package; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub PCI_register { |
19
|
0
|
|
|
0
|
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
|
|
|
|
|
|
|
sub PCI_unregister { |
27
|
0
|
|
|
0
|
0
|
|
return 1; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub S_public { |
31
|
0
|
|
|
0
|
0
|
|
my ($self, $irc) = splice @_, 0, 2; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Parameters are passed as scalar-refs including arrayrefs. |
34
|
0
|
|
|
|
|
|
my $nick = (split /!/, ${$_[0]})[0]; |
|
0
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $channel = ${$_[1]}->[0]; |
|
0
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $msg = ${$_[2]}; |
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
my $reply = |
|
|
0
|
|
|
|
|
|
39
|
|
|
|
|
|
|
($msg =~ /^!vimtips?\b/i) ? $self->_get_vim_tip |
40
|
|
|
|
|
|
|
: ($msg =~ /^!emacstips?\b/i) ? 'use Vim' |
41
|
|
|
|
|
|
|
: ''; |
42
|
0
|
0
|
|
|
|
|
if ($reply) { |
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
|
|
|
|
|
|
|
sub _get_vim_tip { |
52
|
0
|
|
|
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 } # |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
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; |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
__END__ |