Permalink
Browse files

Add SYNOPSIS and correctly croak when a user does not exist

  • Loading branch information...
leto committed Jun 15, 2009
1 parent 1f86785 commit 496143454a7bd973ae72b5aac50c1c8ed8cecbf1
Showing with 23 additions and 4 deletions.
  1. +2 −1 Build.PL
  2. +1 −1 MANIFEST.SKIP
  3. +13 −1 lib/WWW/ItsABot.pm
  4. +7 −1 t/01-basic.t
View
@@ -9,7 +9,8 @@ my $builder = Module::Build->new(
dist_version_from => 'lib/WWW/ItsABot.pm',
dist_abstract => 'Ask itsabot.com if a Twitter user is a bot',
build_requires => {
- 'Test::More' => 0,
+ 'Test::More' => 0,
+ 'Test::Exception' => 0,
},
requires => {
'LWP::Simple' => 0,
View
@@ -1,4 +1,4 @@
-.*\.swp
+.*\.sw?
\.git*
tmp.*
.*\.o
View
@@ -23,6 +23,14 @@ our @EXPORT_OK = qw(is_a_bot);
=head1 SYNOPSIS
+ use WWW::ItsABot qw/is_a_bot/;
+ my $username = 'foobar';
+ if ( is_a_bot($username) ) {
+ print "$username is a bot\n";
+ } else {
+ print "$username is not a bot\n";
+ }
+
=head1 AUTHOR
Jonathan Leto, C<< <jonathan at leto.net> >>
@@ -42,7 +50,11 @@ sub is_a_bot($)
# user,followers,friends,statuses,isabot,follow_ratio,followers_per_tweet
if ( $content ) {
my (@info) = split ',', $content;
- return $info[4] =~ /true/i ? 1 : 0;
+ if (defined $info[4]) {
+ return $info[4] =~ /true/i ? 1 : 0;
+ } else {
+ croak "is_a_bot(): user does not exist";
+ }
} else {
croak "is_a_bot(): did not get a response";
}
View
@@ -3,15 +3,19 @@
use strict;
use warnings;
use lib qw(t/lib);
-use Test::More tests => 2;
+use Test::More tests => 3;
+use Test::Exception;
use WWW::ItsABot qw/is_a_bot/;
+
do {
no warnings 'redefine';
*WWW::ItsABot::get = sub($) {
my $url = shift;
if ( $url =~ m!/User/bot! ){
return "bot,6635,0,753,True,8.81142098274,0.0,2009-06-15 04:35:31.410268\n";
+ } elsif ($url =~ m!/User/dontexist!) {
+ return "{}\n";
} else {
return "user,187,150,662,False,0.509063444109,0.802139037433,2009-06-15 06:03:57.740732\n";
}
@@ -21,3 +25,5 @@ do {
cmp_ok( is_a_bot('bot'),'==', 1, 'bots are bots' );
cmp_ok( is_a_bot('dukeleto'),'==', 0, 'should not be a bot' );
+
+throws_ok( sub { is_a_bot('dontexist') }, qr/user does not exist/, 'Nonexistent users throw an error');

0 comments on commit 4961434

Please sign in to comment.