Skip to content

Commit

Permalink
Add tests and fix True/False => 1/0 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
leto committed Jun 15, 2009
1 parent e543018 commit 1f86785
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions Build.PL
Expand Up @@ -7,6 +7,7 @@ my $builder = Module::Build->new(
license => 'perl', license => 'perl',
dist_author => 'Jonathan Leto <jonathan@leto.net>', dist_author => 'Jonathan Leto <jonathan@leto.net>',
dist_version_from => 'lib/WWW/ItsABot.pm', dist_version_from => 'lib/WWW/ItsABot.pm',
dist_abstract => 'Ask itsabot.com if a Twitter user is a bot',
build_requires => { build_requires => {
'Test::More' => 0, 'Test::More' => 0,
}, },
Expand Down
4 changes: 4 additions & 0 deletions Changes
@@ -0,0 +1,4 @@
Revision history for WWW::ItsABot


* 0.01 - is_a_bot() function
7 changes: 6 additions & 1 deletion MANIFEST
@@ -1,8 +1,13 @@
Build.PL Build.PL
Changes Changes
lib/WWW/ItsABot.pm
MANIFEST MANIFEST
MANIFEST.SKIP
README README
lib/WWW/ItsABot.pm
t/00-load.t t/00-load.t
t/01-basic.t
t/boilerplate.t
t/pod-coverage.t t/pod-coverage.t
t/pod.t t/pod.t
Makefile.PL
META.yml
15 changes: 15 additions & 0 deletions MANIFEST.SKIP
@@ -0,0 +1,15 @@
.*\.swp
\.git*
tmp.*
.*\.o
\.bak
_build
^Build$
blib/*
.*\.data
.*core
foo*
.*\.gz
^tags
Math-Primality
\.prove
5 changes: 4 additions & 1 deletion lib/WWW/ItsABot.pm
Expand Up @@ -2,6 +2,7 @@ package WWW::ItsABot;


use warnings; use warnings;
use strict; use strict;
use base 'Exporter';
use LWP::Simple; use LWP::Simple;
use Carp qw/croak/; use Carp qw/croak/;


Expand All @@ -17,6 +18,8 @@ Version 0.01


our $VERSION = '0.01'; our $VERSION = '0.01';
our $itsabot_url = 'http://www.itsabot.com/User'; our $itsabot_url = 'http://www.itsabot.com/User';
our @EXPORT = ();
our @EXPORT_OK = qw(is_a_bot);


=head1 SYNOPSIS =head1 SYNOPSIS
Expand All @@ -39,7 +42,7 @@ sub is_a_bot($)
# user,followers,friends,statuses,isabot,follow_ratio,followers_per_tweet # user,followers,friends,statuses,isabot,follow_ratio,followers_per_tweet
if ( $content ) { if ( $content ) {
my (@info) = split ',', $content; my (@info) = split ',', $content;
return $info[4]; return $info[4] =~ /true/i ? 1 : 0;
} else { } else {
croak "is_a_bot(): did not get a response"; croak "is_a_bot(): did not get a response";
} }
Expand Down
23 changes: 23 additions & 0 deletions t/01-basic.t
@@ -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.