File Coverage

blib/lib/CPAN/Search/Tester.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package CPAN::Search::Tester;
2              
3 1     1   36449 use Moose;
  0            
  0            
4             use MooseX::Params::Validate;
5             use Moose::Util::TypeConstraints;
6             use namespace::clean;
7              
8             use Carp;
9             use Data::Dumper;
10              
11             use Readonly;
12             use WWW::Mechanize;
13              
14             =head1 NAME
15              
16             CPAN::Search::Tester - Interface to search CPAN module tester.
17              
18             =head1 VERSION
19              
20             Version 0.03
21              
22             =cut
23              
24             our $VERSION = '0.03';
25             Readonly my $URL => 'http://stats.cpantesters.org/cpanmail.html';
26              
27             =head1 DESCRIPTION
28              
29             This module is a very thin wrapper for "Find A Tester" feature provided by cpantesters.org.
30              
31             =cut
32              
33             subtype 'IDORGUID'
34             => as 'Str'
35             => where { (/^\d+$/) || (/^[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+\-[a-z0-9]+$/) };
36              
37             coerce 'IDORGUID'
38             => from 'Num'
39             => via { [ $_ ] }
40             => from 'Str'
41             => via { [ $_ ] };
42              
43             has 'browser' => (is => 'ro', isa => 'WWW::Mechanize', default => sub { return new WWW::Mechanize(autocheck => 1); });
44              
45             =head1 METHODS
46              
47             =head2 search()
48              
49             Search a CPAN Tester for the given ID or GUID. Please use with care and do *NOT* generate spam
50             attacks on testers.
51             Currently CPAN Testers reports are publicly available via the CPAN Testers Reports site, using
52             a unique ID used by 'cpanstats' database or a GUID used by the Metabase data store. Either of
53             these can be used to perform a lookup. The ID or GUID is displayed via the report display on
54             the CPAN Testers Reports site. For example,
55              
56             http://www.cpantesters.org/cpan/report/7019327
57             http://www.cpantesters.org/cpan/report/07019335-b19f-3f77-b713-d32bba55d77f
58              
59             Here 7019327 is the ID and 07019335-b19f-3f77-b713-d32bba55d77f is the GUID.
60              
61             use strict; use warnings;
62             use CPAN::Search::Tester;
63              
64             my $tester = CPAN::Search::Tester->new();
65              
66             print $tester->search('7019327') . "\n";
67             # or
68             print $tester->search('07019335-b19f-3f77-b713-d32bba55d77f') . "\n";
69             # or
70             print $tester->search(id => '7019327') . "\n";
71             # or
72             print $tester->search(guid => '07019335-b19f-3f77-b713-d32bba55d77f') . "\n";
73              
74             =cut
75              
76             around 'search' => sub
77             {
78             my $orig = shift;
79             my $class = shift;
80              
81             if (@_ > 1 && !ref $_[0])
82             {
83             return $class->$orig($_[1]);
84             }
85             else
86             {
87             return $class->$orig(@_);
88             }
89             };
90              
91             sub search
92             {
93             my $self = shift;
94             my ($id) = pos_validated_list(\@_,
95             { isa => 'IDORGUID', coerce => 1, required => 1 },
96             MX_PARAMS_VALIDATE_NO_CACHE => 1);
97              
98             $self->{browser}->get($URL);
99             $self->{browser}->form_number(1);
100             $self->{browser}->field('id', $id);
101             $self->{browser}->submit();
102             my $content = $self->{browser}->content;
103             return "No data found.\n" unless defined $content;
104              
105             if ($content =~ /\<tr\>\<th\>Address\:\<\/th\>\<td\>(.*)\<\/td\>\<\/tr\>/)
106             {
107             return $1;
108             }
109             else
110             {
111             return "No data found.\n";
112             }
113             }
114              
115             =head1 AUTHOR
116              
117             Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
118              
119             =head1 BUGS
120              
121             Please report any bugs or feature requests to C<bug-cpan-search-tester at rt.cpan.org>, or
122             through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPAN-Search-Tester>.
123             I will be notified and then you'll automatically be notified of progress on your bug as I make
124             changes.
125              
126             =head1 SUPPORT
127              
128             You can find documentation for this module with the perldoc command.
129              
130             perldoc CPAN::Search::Tester
131              
132             You can also look for information at:
133              
134             =over 4
135              
136             =item * RT: CPAN's request tracker
137              
138             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=CPAN-Search-Tester>
139              
140             =item * AnnoCPAN: Annotated CPAN documentation
141              
142             L<http://annocpan.org/dist/CPAN-Search-Tester>
143              
144             =item * CPAN Ratings
145              
146             L<http://cpanratings.perl.org/d/CPAN-Search-Tester>
147              
148             =item * Search CPAN
149              
150             L<http://search.cpan.org/dist/CPAN-Search-Tester/>
151              
152             =back
153              
154             =head1 ACKNOWLEDGEMENT
155              
156             This wouldn't have been possible without the service of cpantesters.org.
157              
158             =head1 LICENSE AND COPYRIGHT
159              
160             Copyright 2011 Mohammad S Anwar.
161              
162             This program is free software; you can redistribute it and/or modify it under the terms of
163             either: the GNU General Public License as published by the Free Software Foundation; or the
164             Artistic License.
165              
166             See http://dev.perl.org/licenses/ for more information.
167              
168             =head1 DISCLAIMER
169              
170             This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
171             without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
172              
173             =cut
174              
175             __PACKAGE__->meta->make_immutable;
176             no Moose; # Keywords are removed from the CPAN::Search::Tester package
177             no Moose::Util::TypeConstraints;
178              
179             1; # End of CPAN::Search::Tester