blib/lib/App/Maisha/Shell.pm

filter: Statementstmt 47.9% 244 / 509 Branchbran 18.5% 39 / 210 Conditioncond 11.5% 8 / 69 MC/DCmcdc 0.0% 0 / 43 Subroutinesub 85.5% 89 / 104 Podpod 100% 84 / 84 totaltotal 45.5% 464 / 1019 CC 142 SCAR 34.8
CC
142
Cov
37%
_run_results
132.0
run_user
91.5
run_direct_messages
83.6
CRAP 32.4
« blib/lib/App/Maisha/Plugin/Identica.pm ↑ Summary blib/lib/App/Maisha.pm »
1 package App::Maisha::Shell;
2  
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 10 our $VERSION = '0.22';
7  
8 #----------------------------------------------------------------------------
9  
10 =head1 NAME
11  
12 App::Maisha::Shell - A command line social micro-blog networking tool.
13  
14 =head1 SYNOPSIS
15  
16 use App::Maisha::Shell;
17 my $shell = App::Maisha::Shell->new;
18  
19 =head1 DESCRIPTION
20  
21 This distribution provides the ability to micro-blog via social networking
22 websites and services, such as Identica and Twitter.
23  
24 =cut
25  
26 #----------------------------------------------------------------------------
27 # Library Modules
28  
29 10 ▶use base qw(Term::Shell);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 10 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 10 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 10 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 10 ▶use Module::Pluggable instantiate => 'new', search_path => ['App::Maisha::Plugin'];
Subroutine BEGIN: called CC=1 SCAR=0.0
35 10 ▶use Text::Wrap;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 #----------------------------------------------------------------------------
38 # Variables
39  
40 10 $Text::Wrap::columns = 80;
41  
42 10 my %plugins; # contains all available plugins
43  
44 10 my %months = (
45 'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4,
46 'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8,
47 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12,
48 );
49  
50 10 my %max = (
51 user_timeline => { limit => 3200, count => 200 }, # specific user timelines
52 search_tweets => { limit => 800, count => 100 }, # search lists
53 home_timeline => { limit => 800, count => 200 }, # generic timelines
54 user_lists => { limit => 5000, count => 5000 }, # user lists
55 );
56  
57 #----------------------------------------------------------------------------
58 # Accessors
59  
60 6 ▶sub networks { shift->_elem('networks', @_) }
Subroutine networks: called CC=1 SCAR=0.0
Pod documented
61 12 ▶sub prompt_str { shift->_elem('prompt_str', @_) }
Subroutine prompt_str: called CC=1 SCAR=0.0
Pod documented
62 12 ▶sub tag_str { shift->_elem('tag_str', @_) }
Subroutine tag_str: called CC=1 SCAR=0.0
Pod documented
63 12 ▶sub order { shift->_elem('order', @_) }
Subroutine order: called CC=1 SCAR=0.0
Pod documented
64 20 ▶sub limit { shift->_elem('limit', @_) }
Subroutine limit: called CC=1 SCAR=0.0
Pod documented
65 19 ▶sub services { shift->_elem('services', @_) }
Subroutine services: called CC=1 SCAR=0.0
Pod documented
66 12 ▶sub pager { shift->_elem('pager', @_) }
Subroutine pager: called CC=1 SCAR=0.0
Pod documented
67 12 ▶sub format { shift->_elem('format', @_) }
Subroutine format: called CC=1 SCAR=0.0
Pod documented
68 12 ▶sub chars { shift->_elem('chars', @_) }
Subroutine chars: called CC=1 SCAR=0.0
Pod documented
69 12 ▶sub history { shift->_elem('historyfile', @_) }
Subroutine history: called CC=1 SCAR=0.0
Pod documented
70 12 ▶sub debug { shift->_elem('debug', @_) }
Subroutine debug: called CC=1 SCAR=0.0
Pod documented
71 15 ▶sub error { shift->_elem('error', @_) }
Subroutine error: called CC=1 SCAR=0.0
Pod documented
72  
73 #----------------------------------------------------------------------------
74 # Public API
75  
76 #
77 # Connect/Disconnect
78 #
79  
80 2 ▶sub connect {
Subroutine connect: called CC=5 SCAR=18.2
Pod documented
81 2 my ($self,$plug,$config) = @_;
82  
83 0 ▶ unless($plug) { warn "No plugin supplied\n"; return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($plug) 0 2 2
84  
85 2 ▶ $self->_load_plugins unless(%plugins);
Branch: 1 branch
BranchTrueFalseTotal
unless %plugins 1 1 2
86 2 my $plugin = $self->_get_plugin($plug);
87 2 ▶ if(!$plugin) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($plugin) 0 2 2
88 0 warn "Unable to establish plugin '$plug'\n";
89 0 return;
90 }
91  
92 2 my $status = $plugin->login($config);
93 2 ▶ if(!$status) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($status) 0 2 2
94 0 warn "Login to '$plug' failed\n";
95 0 return;
96 }
97  
98 2 my $services = $self->services;
99 2 push @$services, $plugin;
100 2 $self->services($services);
101 2 $self->_reset_networks;
102 }
103  
104 10 *run_connect = \&connect;
105 2 ▶sub smry_connect { "connect to a service" }
Subroutine smry_connect: called CC=1 SCAR=0.0
Pod documented
106 2 ▶sub help_connect {
Subroutine help_connect: called CC=1 SCAR=0.0
Pod documented
107 2 <<'END';
108  
109 Connects to a named service. Requires the name of the service, together with
110 the username and password to access the service.
111 END
112 }
113  
114  
115 0 ▶sub run_disconnect {
Subroutine run_disconnect: not called CC=2 SCAR=17.9
Pod documented
116 0 my ($self,$plug) = @_;
117  
118 0 ▶ unless($plug) { warn "No plugin supplied\n"; return }
Branch: 1 branch
BranchTrueFalseTotal
unless ($plug) 0 0 0
119  
120 0 my $services = $self->services;
121 0 my @new = grep {ref($_) !~ /^App::Maisha::Plugin::$plug$/} @$services;
122 0 $self->services(\@new);
123 0 $self->_reset_networks;
124 }
125 2 ▶sub smry_disconnect { "disconnect from a service" }
Subroutine smry_disconnect: called CC=1 SCAR=0.0
Pod documented
126 2 ▶sub help_disconnect {
Subroutine help_disconnect: called CC=1 SCAR=0.0
Pod documented
127 2 <<'END';
128  
129 Disconnects from the named service.
130 END
131 }
132  
133  
134 #
135 # Use
136 #
137  
138 0 ▶sub run_use {
Subroutine run_use: not called CC=2 SCAR=17.9
Pod documented
139 0 my ($self,$plug) = @_;
140 0 ▶ if(my $p = $self->_get_plugin($plug)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = $self->_get_plugin($plug)) { } 0 0 0
141 0 my $services = $self->services;
142 0 my @new = grep {ref($_) !~ /^App::Maisha::Plugin::$plug$/} @$services;
143 0 unshift @new, $self->_get_plugin($plug);
144 0 $self->services(\@new);
145 0 $self->_reset_networks;
146 } else {
147 0 warn "Unknown plugin\n";
148 }
149 }
150 2 ▶sub smry_use { "set primary service" }
Subroutine smry_use: called CC=1 SCAR=0.0
Pod documented
151 2 ▶sub help_use {
Subroutine help_use: called CC=1 SCAR=0.0
Pod documented
152 2 <<'END';
153  
154 Set the primary service for message list commands.
155 END
156 }
157  
158 0 ▶sub comp_use {
Subroutine comp_use: not called CC=1 SCAR=6.9
Pod documented
159 0 my ($self, $word, $line, $start_index) = @_;
160 0 my $services = $self->services;
161 my @networks = map {
162 0 ref($_) =~ /^App::Maisha::Plugin::(.+)/; $1;
163 } @$services;
164 0 return grep { /^$word/ } @networks;
165 }
166  
167 #
168 # Followers
169 #
170  
171 1 ▶sub run_followers {
Subroutine run_followers: called CC=1 SCAR=0.0
Pod documented
172 1 my $self = shift;
173 1 $self->_run_snapshot('followers',$max{user_lists},@_);
174 }
175 2 ▶sub smry_followers { "display followers' status" }
Subroutine smry_followers: called CC=1 SCAR=0.0
Pod documented
176 2 ▶sub help_followers {
Subroutine help_followers: called CC=1 SCAR=0.0
Pod documented
177 2 <<'END';
178  
179 Displays the most recent status messages from each of your followers.
180 END
181 }
182  
183  
184 #
185 # Friends
186 #
187  
188 1 ▶sub run_friends {
Subroutine run_friends: called CC=1 SCAR=0.0
Pod documented
189 1 my $self = shift;
190 1 $self->_run_snapshot('friends',$max{user_lists},@_);
191 }
192 2 ▶sub smry_friends { "display friends' status" }
Subroutine smry_friends: called CC=1 SCAR=0.0
Pod documented
193 2 ▶sub help_friends {
Subroutine help_friends: called CC=1 SCAR=0.0
Pod documented
194 2 <<'END';
195  
196 Displays the most recent status messages from each of your friends.
197 END
198 }
199  
200  
201 #
202 # Show User
203 #
204  
205 1 ▶sub run_user {
Subroutine run_user: called CC=12 SCAR=45.2
Pod documented
206 1 my ($self,$user) = @_;
207  
208 1 ▶ $user =~ s/^\@// if($user);
Branch: 1 branch
BranchTrueFalseTotal
if $user 0 1 1
209 1 ▶ unless($user) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user) 1 0 1
210 1 print "no user specified\n\n";
211 1 return;
212 }
213  
214 0 my $ref = { screen_name => $user };
215 0 my $ret = $self->_command('user', $ref);
216  
217 0 print "\n";
218 0 ▶ print "user: $ret->{screen_name}\n" if($ret->{screen_name});
Branch: 1 branch
BranchTrueFalseTotal
if $ret->{"screen_name"} 0 0 0
219 0 ▶ print "name: $ret->{name}\n" if($ret->{name});
Branch: 1 branch
BranchTrueFalseTotal
if $ret->{"name"} 0 0 0
220 0 ▶ print "location: $ret->{location}\n" if($ret->{location});
Branch: 1 branch
BranchTrueFalseTotal
if $ret->{"location"} 0 0 0
221 0 ▶ print "description: $ret->{description}\n" if($ret->{description});
Branch: 1 branch
BranchTrueFalseTotal
if $ret->{"description"} 0 0 0
222 0 ▶ print "url: $ret->{url}\n" if($ret->{url});
Branch: 1 branch
BranchTrueFalseTotal
if $ret->{"url"} 0 0 0
223 0 ▶ print "friends: $ret->{friends_count}\n" if($ret->{friends_count});
Branch: 1 branch
BranchTrueFalseTotal
if $ret->{"friends_count"} 0 0 0
224 0 ▶ print "followers: $ret->{followers_count}\n" if($ret->{followers_count});
Branch: 1 branch
BranchTrueFalseTotal
if $ret->{"followers_count"} 0 0 0
225 0 ▶ print "statuses: $ret->{statuses_count}\n" if($ret->{statuses_count});
Branch: 1 branch
BranchTrueFalseTotal
if $ret->{"statuses_count"} 0 0 0
226 0 ▶ print "status: $ret->{status}{text}\n" if($ret->{status}{text});
Branch: 1 branch
BranchTrueFalseTotal
if $ret->{"status"}{"text"} 0 0 0
227  
228 #use Data::Dumper;
229 #print Dumper($ret);
230 }
231 2 ▶sub smry_user { "display a user profile" }
Subroutine smry_user: called CC=1 SCAR=0.0
Pod documented
232 2 ▶sub help_user {
Subroutine help_user: called CC=1 SCAR=0.0
Pod documented
233 2 <<'END';
234  
235 Displays a user profile.
236 END
237 }
238  
239 0 ▶sub comp_user {
Subroutine comp_user: not called CC=4 SCAR=30.0
Pod documented
240 0 my ($self, $word, $line, $start_index) = @_;
241 0 my $services = $self->services;
242 0 ▶ my $service = $services->[0] || return;
Condition0%0/2
$services->[0] || (return)
l!l
00
MC/DC0%0/1
$services->[0] || (return)
$services->[0]
Truth table0%0/2
A
A= $services->[0]
Aresult
11
00
243 0 ▶ return unless($service && $service->can('users'));
Branch: 1 branch
BranchTrueFalseTotal
unless $service and $service->can("users") 0 0 0
Condition0%0/3
$service and $service->can("users")
!ll&&!rl&&r
000
MC/DC0%0/2
$service and $service->can("users")
$service $service->can("users")
Truth table0%0/3
A and B
A= $serviceB= $service->can("users")
ABresult
0X0
100
111
244  
245 0 my $users = $service->users;
246 0 return grep { /^$word/ } keys %$users;
247 }
248  
249  
250 #
251 # Follow/Unfollow
252 #
253  
254 1 ▶sub run_follow {
Subroutine run_follow: called CC=3 SCAR=12.3
Pod documented
255 1 my ($self,$user) = @_;
256  
257 1 ▶ $user =~ s/^\@// if($user);
Branch: 1 branch
BranchTrueFalseTotal
if $user 0 1 1
258 1 ▶ unless($user) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user) 1 0 1
259 1 print "no user specified\n\n";
260 1 return;
261 }
262  
263 0 my $ref = { screen_name => $user };
264 0 my $ret = $self->_command('follow', $ref);
265 }
266 2 ▶sub smry_follow { "follow a named user" }
Subroutine smry_follow: called CC=1 SCAR=0.0
Pod documented
267 2 ▶sub help_follow {
Subroutine help_follow: called CC=1 SCAR=0.0
Pod documented
268 2 <<'END';
269  
270 Sends a follow request to the name user. If status updates are not protected
271 you can start seeing that user's updates immediately. Otherwise you will have
272 to wait until the user accepts your request.
273 END
274 }
275  
276  
277 1 ▶sub run_unfollow {
Subroutine run_unfollow: called CC=3 SCAR=12.3
Pod documented
278 1 my ($self,$user) = @_;
279  
280 1 ▶ $user =~ s/^\@// if($user);
Branch: 1 branch
BranchTrueFalseTotal
if $user 0 1 1
281 1 ▶ unless($user) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user) 1 0 1
282 1 print "no user specified\n\n";
283 1 return;
284 }
285  
286 0 my $ref = { screen_name => $user };
287 0 my $ret = $self->_command('unfollow', $ref);
288 }
289 2 ▶sub smry_unfollow { "unfollow a named user" }
Subroutine smry_unfollow: called CC=1 SCAR=0.0
Pod documented
290 2 ▶sub help_unfollow {
Subroutine help_unfollow: called CC=1 SCAR=0.0
Pod documented
291 2 <<'END';
292  
293 Allows you to unfollow a user.
294 END
295 }
296  
297  
298 #
299 # Friends Timeline
300 #
301  
302 2 ▶sub run_friends_timeline {
Subroutine run_friends_timeline: called CC=1 SCAR=0.0
Pod documented
303 2 my $self = shift;
304 2 $self->_run_timeline('friends_timeline',$max{home_timeline},undef,@_);
305 }
306  
307 2 ▶sub smry_friends_timeline { "display friends' status as a timeline" }
Subroutine smry_friends_timeline: called CC=1 SCAR=0.0
Pod documented
308 4 ▶sub help_friends_timeline {
Subroutine help_friends_timeline: called CC=1 SCAR=0.0
Pod documented
309 4 <<'END';
310  
311 Displays the most recent status messages within your friends timeline.
312 END
313 }
314  
315 10 *run_ft = \&run_friends_timeline;
316 2 ▶sub smry_ft { "alias to friends_timeline" }
Subroutine smry_ft: called CC=1 SCAR=0.0
Pod documented
317 10 *help_ft = \&help_friends_timeline;
318  
319  
320 #
321 # Public Timeline
322 #
323  
324 2 ▶sub run_public_timeline {
Subroutine run_public_timeline: called CC=1 SCAR=0.0
Pod documented
325 2 my $self = shift;
326 2 $self->_run_timeline('public_timeline',$max{home_timeline},undef,@_);
327 }
328  
329 2 ▶sub smry_public_timeline { "display public status as a timeline" }
Subroutine smry_public_timeline: called CC=1 SCAR=0.0
Pod documented
330 4 ▶sub help_public_timeline {
Subroutine help_public_timeline: called CC=1 SCAR=0.0
Pod documented
331 4 <<'END';
332  
333 Displays the most recent status messages within the public timeline.
334 END
335 }
336  
337 10 *run_pt = \&run_public_timeline;
338 2 ▶sub smry_pt { "alias to public_timeline" }
Subroutine smry_pt: called CC=1 SCAR=0.0
Pod documented
339 10 *help_pt = \&help_public_timeline;
340  
341  
342 #
343 # User Timeline
344 #
345  
346 2 ▶sub run_user_timeline {
Subroutine run_user_timeline: called CC=3 SCAR=11.6
Pod documented
347 2 my $self = shift;
348 2 my $user = shift;
349  
350 2 ▶ $user =~ s/^\@// if($user);
Branch: 1 branch
BranchTrueFalseTotal
if $user 0 2 2
351 2 ▶ unless($user) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user) 2 0 2
352 2 print "no user specified\n\n";
353 2 return;
354 }
355  
356 0 $self->_run_timeline('user_timeline',$max{user_timeline},$user,@_);
357 }
358  
359 2 ▶sub smry_user_timeline { "display named user statuses as a timeline" }
Subroutine smry_user_timeline: called CC=1 SCAR=0.0
Pod documented
360 4 ▶sub help_user_timeline {
Subroutine help_user_timeline: called CC=1 SCAR=0.0
Pod documented
361 4 <<'END';
362  
363 Displays the most recent status messages for a specified user.
364 END
365 }
366 10 *comp_user_timeline = \&comp_user;
367  
368 10 *run_ut = \&run_user_timeline;
369 2 ▶sub smry_ut { "alias to user_timeline" }
Subroutine smry_ut: called CC=1 SCAR=0.0
Pod documented
370 10 *help_ut = \&help_user_timeline;
371 10 *comp_ut = \&comp_user;
372  
373  
374 #
375 # Replies
376 #
377  
378 2 ▶sub run_replies {
Subroutine run_replies: called CC=1 SCAR=0.0
Pod documented
379 2 my $self = shift;
380 2 $self->_run_timeline('replies',$max{home_timeline},undef,@_);
381 }
382  
383 2 ▶sub smry_replies { "display reply messages that refer to you" }
Subroutine smry_replies: called CC=1 SCAR=0.0
Pod documented
384 4 ▶sub help_replies {
Subroutine help_replies: called CC=1 SCAR=0.0
Pod documented
385 4 <<'END';
386  
387 Displays the most recent reply messages that refer to you.
388 END
389 }
390  
391 10 *run_re = \&run_replies;
392 2 ▶sub smry_re { "alias to replies" }
Subroutine smry_re: called CC=1 SCAR=0.0
Pod documented
393 10 *help_re = \&help_replies;
394  
395  
396 #
397 # Direct Messages
398 #
399  
400 2 ▶sub run_direct_messages {
Subroutine run_direct_messages: called CC=18 SCAR=44.3
Pod documented
401 2 my $self = shift;
402 2 ▶ my $frto = @_ && $_[0] =~ /^from|to$/ ? shift : 'to';
Branch: 1 branch
BranchTrueFalseTotal
@_ && $_[0] =~ /^from|to$/ ? : 0 2 2
Condition33%1/3
@_ and $_[0] =~ /^from|to$/
!ll&&!rl&&r
200
MC/DC0%0/2
@_ and $_[0] =~ /^from|to$/
@_ $_[0] =~ /^from|to$/
Truth table33%1/3
A and B
A= @_B= $_[0] =~ /^from|to$/
ABresult
0X0
100
111
403 2 my $num = shift;
404  
405 2 my ($limit,$pages,$count) = $self->_get_limits($max{home_timeline},$num,$self->limit);
406 2 ▶ $pages ||= 1;
Condition50%1/2
$pages ||= 1
l!l
02
MC/DC0%0/1
$pages ||= 1
$pages
Truth table50%1/2
A
A= $pages
Aresult
11
00
407  
408 2 my (@pages,@results,$max_id);
409 2 for my $page (1 .. $pages) {
410 2 my $ref = {};
411 2 ▶ $ref->{max_id} = $max_id-1 if($max_id);
Branch: 1 branch
BranchTrueFalseTotal
if $max_id 0 2 2
412 2 ▶ $ref->{count} = $count if($count);
Branch: 1 branch
BranchTrueFalseTotal
if $count 0 2 2
413  
414 2 my $ret;
415 2 eval { $ret = $self->_command('direct_messages_' . $frto,$ref) };
416  
417 2 ▶ if(($@ || !$ret) && $self->error =~ /This application is not allowed to access or delete your direct messages/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@ || !$ret and $self->error =~ /This application is not allowed to access or delete your direct messages/) 0 2 2
Condition33%2/6
$@ || !$ret and $self->error =~ /This application is not allowed to access or delete your direct messages/
!ll&&!rl&&r
020
$@ or not $ret
l!l&&r!l&&!r
020
MC/DC0%0/3
$@ || !$ret and $self->error =~ /This application is not allowed to access or delete your direct messages/
$@ not $ret $self->error =~ /This application is not allowed to access or delete your direct messages/
Truth table20%1/5
A or not(B) and C
A= $@B= not $retC= $self->error =~ /This application is not allowed to access or delete your direct messages/
ABCresult
00X0
1X00
0100
1X11
0111
418 0 print "WARNING: Your OAuth keys need updating.\n";
419 0 eval { $ret = $self->_command('reauthorize') };
420 0 ▶ return unless($ret);
Branch: 1 branch
BranchTrueFalseTotal
unless $ret 0 0 0
421  
422 # okay retry
423 0 eval { $ret = $self->_command('direct_messages_' . $frto,$ref) };
424 0 ▶ return if($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
425 }
426  
427 2 ▶ last unless($ret);
Branch: 1 branch
BranchTrueFalseTotal
unless $ret 2 0 2
428 0 ▶ last if($max_id && $max_id == $ret->[-1]{id});
Branch: 1 branch
BranchTrueFalseTotal
if $max_id and $max_id == $ret->[-1]{"id"} 0 0 0
Condition0%0/3
$max_id and $max_id == $ret->[-1]{"id"}
!ll&&!rl&&r
000
MC/DC0%0/2
$max_id and $max_id == $ret->[-1]{"id"}
$max_id $max_id == $ret->[-1]{"id"}
Truth table0%0/3
A and B
A= $max_idB= $max_id == $ret->[-1]{"id"}
ABresult
0X0
100
111
429 0 unshift @pages, $ret;
430 0 $max_id = $ret->[-1]{id};
431 }
432  
433 2 ▶ return unless(@pages);
Branch: 1 branch
BranchTrueFalseTotal
unless @pages 2 0 2
434 0 for my $page (@pages) {
435 0 push @results, @$page;
436 }
437 0 ▶ $self->_print_messages($limit,($frto eq 'to' ? 'sender' : 'recipient'),\@results);
Branch: 1 branch
BranchTrueFalseTotal
$frto eq 'to' ? : 0 0 0
438 }
439  
440 2 ▶sub smry_direct_messages { "display direct messages that have been sent to you" }
Subroutine smry_direct_messages: called CC=1 SCAR=0.0
Pod documented
441 4 ▶sub help_direct_messages {
Subroutine help_direct_messages: called CC=1 SCAR=0.0
Pod documented
442 4 <<'END';
443  
444 Displays the direct messages that have been sent to you.
445 END
446 }
447  
448 10 *run_dm = \&run_direct_messages;
449 2 ▶sub smry_dm { "alias to direct_messages" }
Subroutine smry_dm: called CC=1 SCAR=0.0
Pod documented
450 10 *help_dm = \&help_direct_messages;
451  
452  
453 #
454 # Send Message
455 #
456  
457 3 ▶sub run_send_message {
Subroutine run_send_message: called CC=7 SCAR=36.1
Pod documented
458 3 my $self = shift;
459
460 3 ▶ unless($self->line()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->line) 3 0 3
461 3 print "cannot send an empty message\n\n";
462 3 return;
463 }
464  
465 0 my (undef,$user,$mess) = split(/\s+/,$self->line(),3);
466  
467 0 ▶ $user =~ s/^\@// if($user);
Branch: 1 branch
BranchTrueFalseTotal
if $user 0 0 0
468 0 ▶ unless($user) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user) 0 0 0
469 0 print "no user specified\n\n";
470 0 return;
471 }
472  
473 0 ▶ unless(defined $mess && $mess =~ /\S/) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mess and $mess =~ /\S/) 0 0 0
Condition0%0/3
defined $mess and $mess =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $mess and $mess =~ /\S/
defined $mess $mess =~ /\S/
Truth table0%0/3
A and B
A= defined $messB= $mess =~ /\S/
ABresult
0X0
100
111
474 0 print "cannot send an empty message\n\n";
475 0 return;
476 }
477  
478 0 $mess =~ s/^\s+//;
479 0 $mess =~ s/\s+$//;
480 0 my $len = length $mess;
481 0 ▶ if($len > 140) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 140) 0 0 0
482 0 print "message too long: $len/140\n\n";
483 0 return;
484 }
485  
486 0 my $ref = { screen_name => $user, text => $mess };
487 0 $self->_command('send_message', $ref);
488 }
489  
490 2 ▶sub smry_send_message { "send a direct message" }
Subroutine smry_send_message: called CC=1 SCAR=0.0
Pod documented
491 6 ▶sub help_send_message {
Subroutine help_send_message: called CC=1 SCAR=0.0
Pod documented
492 6 <<'END';
493  
494 Posts a message (upto 140 characters), to a named user.
495 END
496 }
497  
498 10 *comp_send_message = \&comp_user;
499 10 *comp_send = \&comp_user;
500 10 *comp_sm = \&comp_user;
501  
502 10 *run_send = \&run_send_message;
503 4 ▶sub smry_send { "alias to send_message" }
Subroutine smry_send: called CC=1 SCAR=0.0
Pod documented
504 10 *help_send = \&help_send_message;
505  
506 10 *run_sm = \&run_send_message;
507 10 *smry_sm = \&smry_send;
508 10 *help_sm = \&help_send_message;
509  
510  
511 #
512 # Update/Say
513 #
514  
515 2 ▶sub run_update {
Subroutine run_update: called CC=8 SCAR=38.4
Pod documented
516 2 my $self = shift;
517
518 2 ▶ unless($self->line()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->line) 2 0 2
519 2 print "cannot send an empty message\n\n";
520 2 return;
521 }
522  
523 0 my (undef,$text) = split(' ',$self->line(),2);
524 0 $text =~ s/^\s+//;
525 0 $text =~ s/\s+$//;
526  
527 0 ▶ unless($text) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($text) 0 0 0
528 0 print "cannot send an empty message\n\n";
529 0 return;
530 }
531  
532 0 my $len = length $text;
533 0 ▶ if($len < 140) {
Branch: 2 branches
BranchTrueFalseTotal
if ($len < 140) { } 0 0 0
elsif ($len > 140) { } 0 0 0
534 0 ▶ my $tag = $self->tag_str || '';
Condition0%0/2
$self->tag_str || ''
l!l
00
MC/DC0%0/1
$self->tag_str || ''
$self->tag_str
Truth table0%0/2
A
A= $self->tag_str
Aresult
11
00
535 0 ▶ $text .= " " if ($text =~ /\S/);
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\S/ 0 0 0
536 0 ▶ $text .= $tag if(length "$text$tag" <= 140);
Branch: 1 branch
BranchTrueFalseTotal
if length "$text$tag" <= 140 0 0 0
537 } elsif($len > 140) {
538 0 print "message too long: $len/140\n\n";
539 0 return;
540 }
541  
542 0 $self->_commands('update', $text);
543 }
544 2 ▶sub smry_update { "post a message" }
Subroutine smry_update: called CC=1 SCAR=0.0
Pod documented
545 4 ▶sub help_update {
Subroutine help_update: called CC=1 SCAR=0.0
Pod documented
546 4 <<'END';
547  
548 Posts a message (upto 140 characters).
549 END
550 }
551  
552 10 *comp_update = \&comp_user;
553  
554 # help
555 10 *run_say = \&run_update;
556 2 ▶sub smry_say { "alias to 'update'" }
Subroutine smry_say: called CC=1 SCAR=0.0
Pod documented
557 10 *help_say = \&help_update;
558 10 *comp_say = \&comp_user;
559  
560  
561 #
562 # Search
563 #
564  
565 0 ▶sub run_search {
Subroutine run_search: not called CC=4 SCAR=30.0
Pod documented
566 0 my $self = shift;
567 0 my (undef,$text) = split(' ',$self->line(),2);
568 0 $text =~ s/^\s+//;
569 0 $text =~ s/\s+$//;
570  
571 0 my $limit;
572 0 ▶ if($text =~ /^(\d+)\s+(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^(\d+)\s+(.*)/) 0 0 0
573 0 ($limit,$text) = ($1,$2);
574 }
575  
576 0 ▶ unless($text) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($text) 0 0 0
577 0 print "cannot search for an empty string\n\n";
578 0 return;
579 }
580  
581 0 my $len = length $text;
582 0 ▶ if($len > 1000) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 1000) 0 0 0
583 0 print "search term is too long: $len/1000\n\n";
584 0 return;
585 }
586 #print "limit=$limit, text=$text\n";
587 0 $self->_run_results('search',$max{search_tweets},$limit,$text);
588 }
589 0 ▶sub smry_search { "search for messages" }
Subroutine smry_search: not called CC=1 SCAR=6.9
Pod documented
590 0 ▶sub help_search {
Subroutine help_search: not called CC=1 SCAR=6.9
Pod documented
591 0 <<'END';
592  
593 Search for messages with a given search term. The given search term can
594 contain up to 1000 characters.
595 END
596 }
597  
598  
599  
600 #
601 # About
602 #
603  
604 2 ▶sub smry_about { "brief summary of maisha" }
Subroutine smry_about: called CC=1 SCAR=0.0
Pod documented
605 2 ▶sub help_about {
Subroutine help_about: called CC=1 SCAR=0.0
Pod documented
606 2 <<'END';
607 Provides a brief summary about maisha.
608 END
609 }
610 1 ▶sub run_about {
Subroutine run_about: called CC=1 SCAR=0.0
Pod documented
611 1 my @time = localtime(time);
612 1 $time[5] += 1900;
613 1 print <<ABOUT;
614  
615 Maisha is a command line application that can interface with a number of online
616 social networking sites. Referred to as micro-blogging, users can post status
617 updates to the likes of Twitter and Identi.ca. Maisha provides the abilty to
618 follow the status updates of friends and see who is following you, as well as
619 allowing you to send updates and send and receive direct messages too.
620  
621 Maisha means "life" in Swahili, and as the application is not tied to any
622 particular online service, it seemed an appropriate choice of name. After all
623 you are posting status updates about your life :)
624  
625 Maisha is written in Perl, and freely available as Open Source under the Perl
626 Artistic license. Copyright (c) 2009-$time[5] Barbie for Grango.org, the Open
627 Source development outlet of Miss Barbell Productions.
628
629 See http://maisha.grango.org for further information.
630  
631 Version: $VERSION
632  
633 ABOUT
634 }
635  
636  
637 #
638 # Version
639 #
640  
641 2 ▶sub smry_version { "display the current version of maisha" }
Subroutine smry_version: called CC=1 SCAR=0.0
Pod documented
642 2 ▶sub help_version {
Subroutine help_version: called CC=1 SCAR=0.0
Pod documented
643 2 <<'END';
644  
645 Displays the current version of maisha.
646 END
647 }
648 1 ▶sub run_version {
Subroutine run_version: called CC=1 SCAR=0.0
Pod documented
649 1 print "\nVersion: $VERSION\n";
650 }
651  
652  
653 #
654 # Debugging
655 #
656  
657 2 ▶sub smry_debug { "turn on/off debugging" }
Subroutine smry_debug: called CC=1 SCAR=0.0
Pod documented
658 2 ▶sub help_debug {
Subroutine help_debug: called CC=1 SCAR=0.0
Pod documented
659 2 <<'END';
660  
661 Some commands may return unexpected results. More verbose output can be
662 returned when debugging is turned on. Set 'debug on' or 'debug off' to
663 turn the debugging functionality on or off respectively.
664 END
665 }
666 1 ▶sub run_debug {
Subroutine run_debug: called CC=4 SCAR=22.9
Pod documented
667 1 my ($self,$state) = @_;
668  
669 1 ▶ if(!$state) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $state) { } 1 0 1
elsif ($state eq 'on') { } 0 0 0
elsif ($state eq 'off') { } 0 0 0
670 1 print "Please use 'on' or 'off' with debug command\n\n";
671 } elsif($state eq 'on') {
672 0 $self->debug(1);
673 0 print "Debugging is ON\n\n";
674 } elsif($state eq 'off') {
675 0 $self->debug(0);
676 0 print "Debugging is OFF\n\n";
677 } else {
678 0 print "Please use 'on' or 'off' with debug command\n\n";
679 }
680 };
681  
682  
683 #
684 # Quit/Exit
685 #
686  
687 4 ▶sub smry_quit { "alias to exit" }
Subroutine smry_quit: called CC=1 SCAR=0.0
Pod documented
688 4 ▶sub help_quit {
Subroutine help_quit: called CC=1 SCAR=0.0
Pod documented
689 4 <<'END';
690  
691 Exits the program.
692 END
693 }
694 0 ▶sub run_quit {
Subroutine run_quit: not called CC=1 SCAR=6.9
Pod documented
695 0 my $self = shift;
696 0 $self->stoploop;
697 }
698  
699 10 *run_q = \&run_quit;
700 10 *smry_q = \&smry_quit;
701 10 *help_q = \&help_quit;
702  
703 0 ▶sub postcmd {
Subroutine postcmd: not called CC=5 SCAR=34.0
Pod documented
704 0 my ($self, $handler, $cmd, $args) = @_;
705 #print "$$handler - $$cmd\n" if($self->debug);
706 0 ▶ return if($handler && $$handler =~ /^(comp|help|smry)_/);
Branch: 1 branch
BranchTrueFalseTotal
if $handler and $$handler =~ /^(comp|help|smry)_/ 0 0 0
Condition0%0/3
$handler and $$handler =~ /^(comp|help|smry)_/
!ll&&!rl&&r
000
MC/DC0%0/2
$handler and $$handler =~ /^(comp|help|smry)_/
$handler $$handler =~ /^(comp|help|smry)_/
Truth table0%0/3
A and B
A= $handlerB= $$handler =~ /^(comp|help|smry)_/
ABresult
0X0
100
111
707 0 ▶ return if($cmd && $$cmd =~ /^(q|quit)$/);
Branch: 1 branch
BranchTrueFalseTotal
if $cmd and $$cmd =~ /^(q|quit)$/ 0 0 0
Condition0%0/3
$cmd and $$cmd =~ /^(q|quit)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$cmd and $$cmd =~ /^(q|quit)$/
$cmd $$cmd =~ /^(q|quit)$/
Truth table0%0/3
A and B
A= $cmdB= $$cmd =~ /^(q|quit)$/
ABresult
0X0
100
111
708  
709 0 push @{$self->{history}}, $self->line;
710 0 print $self->networks;
711 }
712  
713 0 ▶sub preloop {
Subroutine preloop: not called CC=6 SCAR=37.4
Pod documented
714 0 my $self = shift;
715 0 my $file = $self->history;
716 0 ▶ if($file && -f $file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and -f $file) 0 0 0
Condition0%0/3
$file and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$file and -f $file
$file -f $file
Truth table0%0/3
A and B
A= $fileB= -f $file
ABresult
0X0
100
111
717 0 ▶ my $fh = IO::File->new($file,'r') or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($file, "r") or return 0 0 0
718 0 ▶ while(<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
719 0 s/\s+$//;
720 0 ▶ next unless($_);
Branch: 1 branch
BranchTrueFalseTotal
unless $_ 0 0 0
721 0 $self->term->addhistory($_);
722 0 push @{$self->{history}}, $_;
723 }
724 }
725 }
726  
727 0 ▶sub postloop {
Subroutine postloop: not called CC=6 SCAR=37.4
Pod documented
728 0 my $self = shift;
729 0 ▶ if(my $file = $self->history) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $file = $self->history) 0 0 0
730 0 ▶ my @history = grep { $_ && $_ !~ /^(q|quit)$/ } @{$self->{history}};
Condition0%0/3
$_ && !($_ =~ /^(q|quit)$/)
!ll&&!rl&&r
000
MC/DC0%0/2
$_ && !($_ =~ /^(q|quit)$/)
$_ !($_ =~ /^(q|quit)$/)
Truth table0%0/3
A && not(B)
A= $_B= !($_ =~ /^(q|quit)$/)
ABresult
0X0
100
111
731 0 ▶ if(@history) {
Branch: 1 branch
BranchTrueFalseTotal
if (@history) 0 0 0
732 0 mkpath(dirname($file));
733 0 ▶ my $fh = IO::File->new($file,'w+') or return;
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new($file, "w+") or return 0 0 0
734 0 ▶ splice( @history, 0, (scalar(@history) - 100)) if(@history > 100);
Branch: 1 branch
BranchTrueFalseTotal
if @history > 100 0 0 0
735 0 print $fh join("\n", @history);
736 0 $fh->close;
737 }
738 }
739 }
740  
741 #----------------------------------------------------------------------------
742 # Private Methods
743  
744 2 ▶sub _reset_networks {
Subroutine _reset_networks: called CC=3 SCAR=11.0
745 2 my $self = shift;
746 2 my $first = 1;
747 2 my $str = "\nNetworks: ";
748 2 my $services = $self->services;
749 2 for my $item (@$services) {
750 3 my $ref = ref($item);
751 3 $ref =~ s/^App::Maisha::Plugin:://;
752 3 ▶ $str .= $first ? "[$ref]" : " $ref";
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 2 1 3
753 3 $first = 0;
754 }
755 2 $str .= "\n";
756 2 $self->networks($str);
757 }
758  
759 156 ▶sub _elem {
Subroutine _elem: called CC=2 SCAR=6.9
760 156 my $self = shift;
761 156 my $name = shift;
762 156 my $value = $self->{$name};
763 156 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 72 84 156
764 72 $self->{$name} = shift;
765 }
766 156 return $value;
767 }
768  
769 2 ▶sub _run_snapshot {
Subroutine _run_snapshot: called CC=11 SCAR=39.6
770 2 my ($self,$cmd,$max,$num) = @_;
771 2 my (@pages,@results,$max_id);
772 2 my ($limit,$pages,$count) = $self->_get_limits($max,$num);
773  
774 2 ▶ if($pages) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pages) { } 0 2 2
775 0 for my $page (1 .. $pages) {
776 0 my $ref = {};
777 0 ▶ $ref->{max_id} = $max_id-1 if($max_id);
Branch: 1 branch
BranchTrueFalseTotal
if $max_id 0 0 0
778 0 ▶ $ref->{count} = $count if($count);
Branch: 1 branch
BranchTrueFalseTotal
if $count 0 0 0
779  
780 0 my $ret;
781 0 eval { $ret = $self->_command($cmd,$ref) };
782 0 ▶ last unless($ret);
Branch: 1 branch
BranchTrueFalseTotal
unless $ret 0 0 0
783 0 ▶ last if($max_id && $max_id == $ret->[-1]{id});
Branch: 1 branch
BranchTrueFalseTotal
if $max_id and $max_id == $ret->[-1]{"id"} 0 0 0
Condition0%0/3
$max_id and $max_id == $ret->[-1]{"id"}
!ll&&!rl&&r
000
MC/DC0%0/2
$max_id and $max_id == $ret->[-1]{"id"}
$max_id $max_id == $ret->[-1]{"id"}
Truth table0%0/3
A and B
A= $max_idB= $max_id == $ret->[-1]{"id"}
ABresult
0X0
100
111
784 0 unshift @pages, @$ret;
785 0 $max_id = $ret->[-1]{id};
786 }
787 } else {
788 2 my $ret;
789 2 eval { $ret = $self->_command($cmd) };
790 2 ▶ push @pages, @$ret if($ret);
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 2 2
791 }
792  
793 2 ▶ return unless(@pages);
Branch: 1 branch
BranchTrueFalseTotal
unless @pages 2 0 2
794 0 for my $page (@pages) {
795 0 push @results, @$page;
796 }
797 0 $self->_print_messages($limit,undef,\@results);
798 }
799  
800 0 ▶sub _run_results {
Subroutine _run_results: not called CC=11 SCAR=48.8
801 0 my ($self,$cmd,$max,$num,$term) = @_;
802 0 my (@pages,@results,$max_id);
803 0 my ($limit,$pages,$count) = $self->_get_limits($max,$num);
804  
805 0 ▶ if($pages) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pages) { } 0 0 0
806 0 for my $page (1 .. $pages) {
807 0 my $ref = {};
808 0 ▶ $ref->{max_id} = $max_id-1 if($max_id);
Branch: 1 branch
BranchTrueFalseTotal
if $max_id 0 0 0
809 0 ▶ $ref->{count} = $count if($count);
Branch: 1 branch
BranchTrueFalseTotal
if $count 0 0 0
810  
811 0 my $ret;
812 0 eval { $ret = $self->_command($cmd,$term,$ref) };
813 0 ▶ last unless($ret);
Branch: 1 branch
BranchTrueFalseTotal
unless $ret 0 0 0
814 0 ▶ last if($max_id && $max_id == $ret->[-1]{id});
Branch: 1 branch
BranchTrueFalseTotal
if $max_id and $max_id == $ret->[-1]{"id"} 0 0 0
Condition0%0/3
$max_id and $max_id == $ret->[-1]{"id"}
!ll&&!rl&&r
000
MC/DC0%0/2
$max_id and $max_id == $ret->[-1]{"id"}
$max_id $max_id == $ret->[-1]{"id"}
Truth table0%0/3
A and B
A= $max_idB= $max_id == $ret->[-1]{"id"}
ABresult
0X0
100
111
815 0 unshift @pages, [ @{$ret->{results}} ];
816 0 $max_id = $ret->{results}[-1]{id};
817 }
818 } else {
819 0 my $ret;
820 0 eval { $ret = $self->_command($cmd,$term) };
821 0 ▶ push @pages, [ @{$ret->{results}} ] if($ret);
Branch: 1 branch
BranchTrueFalseTotal
if $ret 0 0 0
822 }
823  
824 0 ▶ return unless(@pages);
Branch: 1 branch
BranchTrueFalseTotal
unless @pages 0 0 0
825 0 for my $page (@pages) {
826 0 push @results, @$page;
827 }
828 0 $self->_print_messages($limit,undef,\@results);
829 }
830  
831 6 ▶sub _run_timeline {
Subroutine _run_timeline: called CC=11 SCAR=31.2
832 6 my ($self,$cmd,$max,$user,$num) = @_;
833 6 my ($limit,$pages,$count) = $self->_get_limits($max,$num,$self->limit);
834  
835 6 ▶ $pages ||= 1;
Condition50%1/2
$pages ||= 1
l!l
06
MC/DC0%0/1
$pages ||= 1
$pages
Truth table50%1/2
A
A= $pages
Aresult
11
00
836  
837 6 my (@pages,@results,$max_id);
838 6 for my $page (1 .. $pages) {
839 6 my $ref = {};
840 6 ▶ $ref->{screen_name} = $user if($user);
Branch: 1 branch
BranchTrueFalseTotal
if $user 0 6 6
841 6 ▶ $ref->{max_id} = $max_id-1 if($max_id);
Branch: 1 branch
BranchTrueFalseTotal
if $max_id 0 6 6
842 6 ▶ $ref->{count} = $count if($count);
Branch: 1 branch
BranchTrueFalseTotal
if $count 0 6 6
843  
844 6 my $ret;
845 6 eval { $ret = $self->_command($cmd,$ref) };
846 6 ▶ last unless($ret);
Branch: 1 branch
BranchTrueFalseTotal
unless $ret 6 0 6
847 0 ▶ last if($max_id && $max_id == $ret->[-1]{id});
Branch: 1 branch
BranchTrueFalseTotal
if $max_id and $max_id == $ret->[-1]{"id"} 0 0 0
Condition0%0/3
$max_id and $max_id == $ret->[-1]{"id"}
!ll&&!rl&&r
000
MC/DC0%0/2
$max_id and $max_id == $ret->[-1]{"id"}
$max_id $max_id == $ret->[-1]{"id"}
Truth table0%0/3
A and B
A= $max_idB= $max_id == $ret->[-1]{"id"}
ABresult
0X0
100
111
848 0 unshift @pages, $ret;
849 0 $max_id = $ret->[-1]{id};
850 }
851  
852 6 ▶ return unless(@pages);
Branch: 1 branch
BranchTrueFalseTotal
unless @pages 6 0 6
853 0 for my $page (@pages) {
854 0 push @results, @$page;
855 }
856 0 $self->_print_messages($limit,'user',\@results);
857 }
858  
859 10 ▶sub _command {
Subroutine _command: called CC=7 SCAR=33.5
860 10 my $self = shift;
861 10 my $cmd = shift;
862  
863 10 $self->error('');
864  
865 10 my $services = $self->services;
866 10 ▶ return unless(defined $services && @$services);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $services and @$services 10 0 10
Condition33%1/3
defined $services and @$services
!ll&&!rl&&r
1000
MC/DC0%0/2
defined $services and @$services
defined $services @$services
Truth table33%1/3
A and B
A= defined $servicesB= @$services
ABresult
0X0
100
111
867  
868 0 my $service = $services->[0];
869 0 ▶ return unless(defined $service);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $service 0 0 0
870  
871 0 my $method = "api_$cmd";
872 0 my $ret;
873 0 eval { $ret = $service->$method(@_) };
874  
875 0 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not $ret) { } 0 0 0
876 0 ▶ print "Command $cmd failed :(" . ($self->debug ? " [$@]" : '') . "\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->debug ? : 0 0 0
877 0 $self->error($@);
878 } elsif(!$ret) {
879 0 print "Command $cmd failed :(\n";
880 } else {
881 #print "$cmd ok\n";
882 }
883  
884 0 return $ret;
885 }
886  
887 0 ▶sub _commands {
Subroutine _commands: not called CC=8 SCAR=42.8
888 0 my $self = shift;
889 0 my $cmd = shift;
890  
891 0 $self->error('');
892  
893 0 my $services = $self->services;
894 0 ▶ return unless(defined $services && @$services);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $services and @$services 0 0 0
Condition0%0/3
defined $services and @$services
!ll&&!rl&&r
000
MC/DC0%0/2
defined $services and @$services
defined $services @$services
Truth table0%0/3
A and B
A= defined $servicesB= @$services
ABresult
0X0
100
111
895  
896 0 for my $service (@$services) {
897 0 ▶ next unless(defined $service);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $service 0 0 0
898  
899 0 my $class = ref($service);
900 0 $class =~ s/^App::Maisha::Plugin:://;
901  
902 0 my $method = "api_$cmd";
903 0 my $ret;
904 0 eval { $ret = $service->$method(@_) };
905  
906 0 ▶ if ($@) {
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 0 0
elsif (not $ret) { } 0 0 0
907 0 ▶ print "[$class] Command $cmd failed :(" . ($self->debug ? " [$@]" : '') . "\n";
Branch: 1 branch
BranchTrueFalseTotal
$self->debug ? : 0 0 0
908 0 $self->error("[$class] $@");
909 } elsif(!$ret) {
910 0 print "[$class] Command $cmd failed :(\n";
911 } else {
912 0 print "[$class] $cmd ok\n";
913 }
914 }
915  
916 0 return 1;
917 }
918  
919 0 ▶sub _print_messages {
Subroutine _print_messages: not called CC=5 SCAR=34.0
920 0 my ($self,$limit,$who,$ret) = @_;
921  
922 0 $Text::Wrap::columns = $self->chars;
923  
924 0 ▶ my @recs = $self->order =~ /^asc/i ? @$ret : reverse @$ret;
Branch: 1 branch
BranchTrueFalseTotal
$self->order =~ /^asc/i ? : 0 0 0
925 0 ▶ splice(@recs,$limit) if($limit && $limit < scalar(@recs));
Branch: 1 branch
BranchTrueFalseTotal
if $limit and $limit < scalar @recs 0 0 0
Condition0%0/3
$limit and $limit < scalar @recs
!ll&&!rl&&r
000
MC/DC0%0/2
$limit and $limit < scalar @recs
$limit $limit < scalar @recs
Truth table0%0/3
A and B
A= $limitB= $limit < scalar @recs
ABresult
0X0
100
111
926 0 @recs = reverse @recs;
927  
928 my $msgs = "\n" .
929 join("\n", map {
930 0 wrap('',' ',$self->_format_message($_,$who))
931 } @recs ) . "\n";
932 0 ▶ if ($self->pager) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->pager) { } 0 0 0
933 0 $self->page($msgs);
934 } else {
935 0 print $msgs;
936 }
937 }
938  
939 0 ▶sub _format_message {
Subroutine _format_message: not called CC=6 SCAR=37.4
940 0 my ($self,$mess,$who) = @_;
941 0 my ($user,$text);
942  
943 0 my $network = $self->networks();
944 0 $network =~ s!^.*?\[([^\]]+)\].*!$1!s;
945  
946 0 my $timestamp = $mess->{created_at};
947 0 my ($M,$D,$T,$Y) = $timestamp =~ /\w+\s+(\w+)\s+(\d+)\s+([\d:]+)\s+\S+\s+(\d+)/; # Sat Oct 13 19:01:19 +0000 2012
948 0 ▶ ($D,$M,$Y,$T) = $timestamp =~ /\w+,\s+(\d+)\s+(\w+)\s+(\d+)\s+([\d:]+)/ unless($M); # Sat, 13 Oct 2012 19:01:19 +0000
Branch: 1 branch
BranchTrueFalseTotal
unless $M 0 0 0
949  
950 0 my $datetime = sprintf "%02d/%02d/%04d %s", $D, $months{$M}, $Y, $T;
951 0 my $date = sprintf "%02d/%02d/%04d", $D, $months{$M}, $Y;
952 0 my $time = $T;
953  
954 0 ▶ if($who) {
Branch: 1 branch
BranchTrueFalseTotal
if ($who) { } 0 0 0
955 0 $user = $mess->{$who}{screen_name};
956 0 $text = $mess->{text};
957 } else {
958 0 ▶ $user = $mess->{screen_name} || $mess->{from_user};
Condition0%0/3
$mess->{'screen_name'} || $mess->{'from_user'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$mess->{'screen_name'} || $mess->{'from_user'}
$mess->{'screen_name'} $mess->{'from_user'}
Truth table0%0/3
A || B
A= $mess->{'screen_name'}B= $mess->{'from_user'}
ABresult
1X1
011
000
959 0 ▶ $text = $mess->{status}{text} || $mess->{text};
Condition0%0/3
$mess->{'status'}{'text'} || $mess->{'text'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$mess->{'status'}{'text'} || $mess->{'text'}
$mess->{'status'}{'text'} $mess->{'text'}
Truth table0%0/3
A || B
A= $mess->{'status'}{'text'}B= $mess->{'text'}
ABresult
1X1
011
000
960 0 ▶ $text ||= '';
Condition0%0/2
$text ||= ""
l!l
00
MC/DC0%0/1
$text ||= ""
$text
Truth table0%0/2
A
A= $text
Aresult
11
00
961 }
962  
963 0 my $format = $self->format;
964 0 $format =~ s!\%U!$user!g;
965 0 $format =~ s!\%M!$text!g;
966 0 $format =~ s!\%T!$timestamp!g;
967 0 $format =~ s!\%D!$datetime!g;
968 0 $format =~ s!\%t!$time!g;
969 0 $format =~ s!\%d!$date!g;
970 0 $format =~ s!\%N!$network!g;
971 0 return $format;
972 }
973  
974 10 ▶sub _get_limits {
Subroutine _get_limits: called CC=7 SCAR=33.9
975 10 my ($self,$max,$limit,$default) = @_;
976 10 ▶ $limit ||= $default;
Condition33%1/3
$limit ||= $default
l!l&&r!l&&!r
0010
MC/DC0%0/2
$limit ||= $default
$limit $default
Truth table33%1/3
A ||= B
A= $limitB= $default
ABresult
1X1
011
000
977 10 ▶ return unless($limit);
Branch: 1 branch
BranchTrueFalseTotal
unless $limit 10 0 10
978  
979 0 ▶ return unless($limit =~ /^\d+$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $limit =~ /^\d+$/ 0 0 0
980 0 ▶ $limit = $max->{limit} if($limit > $max->{limit});
Branch: 1 branch
BranchTrueFalseTotal
if $limit > $max->{"limit"} 0 0 0
981 0 my $count = $max->{count};
982  
983 0 ▶ return($limit,1,$limit) if($limit <= $count);
Branch: 1 branch
BranchTrueFalseTotal
if $limit <= $count 0 0 0
984  
985 0 ▶ my $pages = int($limit / $count) + ($limit % $count ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$limit % $count ? : 0 0 0
986 0 return($limit,$pages,$count);
987 }
988  
989 1 ▶sub _load_plugins {
Subroutine _load_plugins: called CC=3 SCAR=11.0
990 1 my $self = shift;
991 1 for my $plugin ($self->plugins()) {
992 4 my $class = ref($plugin);
993 4 $class =~ s/^App::Maisha::Plugin:://;
994 #print STDERR "CLASS=$class, PLUGIN=$plugin\n";
995 4 ▶ $plugins{$class} = $plugin unless($class eq 'Base');
Branch: 1 branch
BranchTrueFalseTotal
unless $class eq "Base" 3 1 4
996 }
997 }
998  
999 2 ▶sub _get_plugin {
Subroutine _get_plugin: called CC=3 SCAR=11.7
1000 2 my $self = shift;
1001 2 ▶ my $class = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $class = shift() or return 2 0 2
1002 2 ▶ return $plugins{$class} || undef;
Condition50%1/2
$plugins{$class} || undef
l!l
20
MC/DC0%0/1
$plugins{$class} || undef
$plugins{$class}
Truth table50%1/2
A
A= $plugins{$class}
Aresult
11
00
1003 }
1004  
1005 10 1;
1006  
1007 __END__
« blib/lib/App/Maisha/Plugin/Identica.pm ↑ Summary blib/lib/App/Maisha.pm »