Permalink
Browse files

Add tests and fix True/False => 1/0 bug

  • Loading branch information...
1 parent e543018 commit 1f867852819d672c87e2f28ec17ef5f45928fcbf @leto committed Jun 15, 2009
Showing with 53 additions and 2 deletions.
  1. +1 −0 Build.PL
  2. +4 −0 Changes
  3. +6 −1 MANIFEST
  4. +15 −0 MANIFEST.SKIP
  5. +4 −1 lib/WWW/ItsABot.pm
  6. +23 −0 t/01-basic.t
View
@@ -7,6 +7,7 @@ my $builder = Module::Build->new(
license => 'perl',
dist_author => 'Jonathan Leto <jonathan@leto.net>',
dist_version_from => 'lib/WWW/ItsABot.pm',
+ dist_abstract => 'Ask itsabot.com if a Twitter user is a bot',
build_requires => {
'Test::More' => 0,
},
View
@@ -0,0 +1,4 @@
+Revision history for WWW::ItsABot
+
+
+* 0.01 - is_a_bot() function
View
@@ -1,8 +1,13 @@
Build.PL
Changes
+lib/WWW/ItsABot.pm
MANIFEST
+MANIFEST.SKIP
README
-lib/WWW/ItsABot.pm
t/00-load.t
+t/01-basic.t
+t/boilerplate.t
t/pod-coverage.t
t/pod.t
+Makefile.PL
+META.yml
View
@@ -0,0 +1,15 @@
+.*\.swp
+\.git*
+tmp.*
+.*\.o
+\.bak
+_build
+^Build$
+blib/*
+.*\.data
+.*core
+foo*
+.*\.gz
+^tags
+Math-Primality
+\.prove
View
@@ -2,6 +2,7 @@ package WWW::ItsABot;
use warnings;
use strict;
+use base 'Exporter';
use LWP::Simple;
use Carp qw/croak/;
@@ -17,6 +18,8 @@ Version 0.01
our $VERSION = '0.01';
our $itsabot_url = 'http://www.itsabot.com/User';
+our @EXPORT = ();
+our @EXPORT_OK = qw(is_a_bot);
=head1 SYNOPSIS
@@ -39,7 +42,7 @@ sub is_a_bot($)
# user,followers,friends,statuses,isabot,follow_ratio,followers_per_tweet
if ( $content ) {
my (@info) = split ',', $content;
- return $info[4];
+ return $info[4] =~ /true/i ? 1 : 0;
} else {
croak "is_a_bot(): did not get a response";
}
View
@@ -0,0 +1,23 @@
+#!/usr/bin/env perl -w
+
+use strict;
+use warnings;
+use lib qw(t/lib);
+use Test::More tests => 2;
+
+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";
+ } else {
+ return "user,187,150,662,False,0.509063444109,0.802139037433,2009-06-15 06:03:57.740732\n";
+ }
+ };
+};
+
+cmp_ok( is_a_bot('bot'),'==', 1, 'bots are bots' );
+
+cmp_ok( is_a_bot('dukeleto'),'==', 0, 'should not be a bot' );

0 comments on commit 1f86785

Please sign in to comment.