blib/lib/Bot/BasicBot/Pluggable/Module/Twitter.pm

filter: Statementstmt 39.2% 20 / 51 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 100% 4 / 4 totaltotal 37.9% 30 / 79 CC 10 SCAR 32.3
CC
10
Cov
31%
said
56.0
set
20.0
init
2.0
CRAP 25.4
↑ Summary
1 package Bot::BasicBot::Pluggable::Module::Twitter;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Bot::BasicBot::Pluggable::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use base qw(Bot::BasicBot::Pluggable::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use Net::Twitter;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $VERSION = '0.0.3';
13  
14 =head1 NAME
15  
16 Bot::BasicBot::Pluggable::Module::Twitter - Post message to twitter
17  
18  
19 =head1 SYNOPSIS
20  
21 $bot->load( "Twitter" );
22 my $twi_handler = $bot->handler( "Twitter" );
23 $twi_handler->set(
24 { username => "myusername",
25 password => "mypassword",
26 }
27 );
28  
29 =head1 DESCRIPTION
30  
31 A plugin module for L<Bot::BasicBot::Pluggable> to send message to a twitter account.
32  
33 =head2 METHODS
34  
35 =cut
36  
37 =head3 init
38  
39 =cut
40  
41 0 ▶sub init {
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
42 0 my $self = shift;
43 }
44  
45 =head3 help
46  
47 !help
48
49 will return a help message
50  
51 =cut
52  
53 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod documented
54 0 my $self = shift;
55 0 my $mess = "!twitter <str> : will post a message to twitter";
56 0 $mess
57 .= "\n!twitter_all : will return the last 5 public messages from the public timeline";
58 0 return $mess;
59 }
60  
61 =head3 said
62  
63 !twitter my message
64 !twitter_all
65
66 will send to twitter your message
67 will get the last 5 messages from the public timeline
68  
69 =cut
70  
71 0 ▶sub said {
Subroutine said: not called CC=7 SCAR=40.3
Pod documented
72 0 my ( $self, $mess, $pri ) = @_;
73  
74 0 ▶ return unless $pri == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $pri == 2 0 0 0
75  
76 0 $self->{ body } = $mess->{ body };
77 0 $self->{ who } = $mess->{ who };
78 0 $self->{ channel } = $mess->{ channel };
79  
80 0 ▶ if ( $self->{ body } =~ /^!twitter\s(.*)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'body'} =~ /^!twitter\s(.*)$/) { } 0 0 0
elsif ($self->{'body'} =~ /^!twitter_all/) { } 0 0 0
81 0 my $result = $self->{ twit }->update( $1 );
82 0 ▶ if ( !defined $result ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $result) { } 0 0 0
83 $self->tell( $self->{ channel },
84 0 $self->{ who } . ": an error occurs." );
85 }
86 else {
87 $self->tell( $self->{ channel },
88 0 $self->{ who } . ": consider it noted." );
89 }
90 }
91 elsif ( $self->{ body } =~ /^!twitter_all/ ) {
92 0 my $result = $self->{ twit }->public_timeline;
93 0 my $i = 0;
94 0 foreach my $t ( @{ $result } ) {
95 0 my $str = $t->{ user }->{ name }. " :". $t->{text};
96 0 $self->tell( $self->{ channel }, $str );
97 0 $i++;
98 0 ▶ last if $i == 5;
Branch: 1 branch
BranchTrueFalseTotal
if $i == 5 0 0 0
99 }
100 }
101 }
102  
103 =head3 set
104  
105 $twitter_handler->set(
106 { username => "myusername",
107 password => "mypassword",
108 }
109 );
110
111 will set the username and the password for the bot.
112  
113 =cut
114  
115 0 ▶sub set {
Subroutine set: not called CC=4 SCAR=30.0
Pod documented
116 0 my ( $self, $params ) = @_;
117  
118 0 foreach my $key ( keys %{ $params } ) {
119 0 $self->{ $key } = $$params{ $key };
120 }
121  
122 0 ▶ croak "Error: no twitter username specified" unless $self->{ username };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"username"} 0 0 0
123 0 ▶ croak "Error: no twitter password specified" unless $self->{ password };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"password"} 0 0 0
124  
125 $self->{ twit } = Net::Twitter->new(
126 username => $self->{ username },
127 password => $self->{ password }
128 0 );
129  
130 0 return $self;
131 }
132  
133 2 1;
134 __END__
↑ Summary