Skip to content
Browse files

starting inquery tests

  • Loading branch information...
1 parent 6bc7dd6 commit 55a18019c2be7577e3c0d5dfcd1e3ecfefa19ef2 @semuel committed Jun 28, 2013
Showing with 88 additions and 8 deletions.
  1. +3 −5 lib/Dist/Surveyor.pm
  2. +61 −2 lib/Dist/Surveyor/Inquiry.pm
  3. +1 −1 t/01-makecpan.t
  4. +23 −0 t/02-inquery.t
View
8 lib/Dist/Surveyor.pm
@@ -62,8 +62,6 @@ GetOptions(
$opt_verbose++ if $opt_debug;
$opt_perlver = version->parse($opt_perlver || $])->numify;
-Dist::Surveyor::Inquiry->init_cache(!$opt_uncached);
-
my $major_error_count = 0; # exit status
sub main {
@@ -86,19 +84,19 @@ sub main {
$::DEBUG = $opt_debug;
$::VERBOSE = $opt_verbose;
- Dist::Surveyor::Inquiry->perma_cache();
+ Dist::Surveyor::Inquiry->perma_cache() unless $opt_uncached;
my @installed_releases = determine_installed_releases(@libdirs);
write_fields(\@installed_releases, $opt_format, [split ' ', $opt_output], \*STDOUT);
warn sprintf "Completed survey in %.1f minutes using %d metacpan calls.\n",
- (time-$^T)/60, $metacpan_calls;
+ (time-$^T)/60, $Dist::Surveyor::Inquiry::metacpan_calls;
if ($opt_makecpan) {
require Dist::Surveyor::MakeCpan;
my $cpan = Dist::Surveyor::MakeCpan->new(
- $opt_makecpan, PROGNAME, $distro_key_mod_names, $opt_verbose);
+ $opt_makecpan, PROGNAME, $distro_key_mod_names);
warn "Updating $opt_makecpan for ".@installed_releases." releases...\n";
View
63 lib/Dist/Surveyor/Inquiry.pm
@@ -8,6 +8,40 @@ use Dist::Surveyor::DB_File; # internal
use LWP::UserAgent;
use JSON;
+=head1 NAME
+
+Dist::Surveyor::Inquiry - Handling the meta-cpan API access for Dist::Surveyor
+
+=head1 DESCRIPTION
+
+There are a few things that needed to be known in this module:
+
+=over
+
+=item *
+
+$metacpan_size - internally defined global to limit the maximum size of
+every API call
+
+=item *
+
+$metacpan_calls - internally defined global counting how many API call happen.
+
+=item *
+
+This module checks $::DEBUG and $::VERBOSE for obvious proposes.
+
+=item *
+
+For initating cache-on-disk, call Dist::Surveyor::Inquiry->perma_cache()
+(this should be usually done, except in testing environment)
+
+=back
+
+=head1 FUNCTIONS
+
+=cut
+
# We have to limit the number of results when using MetaCPAN::API.
# We can'r make it too large as it hurts the server (it preallocates)
# but need to make it large enough for worst case distros (eg eBay-API).
@@ -224,8 +258,27 @@ sub get_candidate_cpan_dist_releases_fallback {
return \%dists;
}
-# this can be called for all sorts of releases that are only vague possibilities
-# and aren't actually installed, so generally it's quiet
+=head2 get_module_versions_in_release($author, $release)
+
+Receive release info, such as:
+
+ get_module_versions_in_release('SEMUELF', 'Dist-Surveyor-0.009')
+
+And returns a hashref, that contains one entry for each module that exists
+in the release. module information is the format:
+
+ 'Dist::Surveyor' => {
+ 'version' => '0.009',
+ 'name' => 'Dist::Surveyor',
+ 'path' => 'lib/Dist/Surveyor.pm',
+ 'size' => 43879
+ },
+
+this function can be called for all sorts of releases that are only vague
+possibilities and aren't actually installed, so generally it's quiet
+
+=cut
+
sub get_module_versions_in_release {
my ($author, $release) = @_;
@@ -318,4 +371,10 @@ sub get_module_versions_in_release {
return \%modules_in_release;
}
+=head1 License, Copyright
+
+Please see L<Dist::Surveyor> for details
+
+=cut
+
1;
View
2 t/01-makecpan.t
@@ -21,7 +21,7 @@ ok(-e $cpan_dir, "MiniCPAN directory created");
my $rel = {
download_url => 'http://cpan.metacpan.org/authors/id/S/SE/SEMUELF/Dist-Surveyor-0.009.tar.gz',
- url => '',
+ url => 'authors/id/S/SE/SEMUELF/Dist-Surveyor-0.009.tar.gz',
author => 'SEMUELF',
name => 'Dist-Surveyor-0.009',
distribution => 'Dist-Surveyor',
View
23 t/02-inquery.t
@@ -0,0 +1,23 @@
+use strict;
+use warnings;
+use Dist::Surveyor::Inquiry;
+use Test::More;
+
+my $module_data = get_module_versions_in_release('SEMUELF', 'Dist-Surveyor-0.009');
+my $expected = {
+ 'Dist::Surveyor' => {
+ 'version' => '0.009',
+ 'name' => 'Dist::Surveyor',
+ 'path' => 'lib/Dist/Surveyor.pm',
+ 'size' => 43879
+ },
+ 'Dist::Surveyor::DB_File' => {
+ 'version' => '0.009',
+ 'name' => 'Dist::Surveyor::DB_File',
+ 'path' => 'lib/Dist/Surveyor/DB_File.pm',
+ 'size' => 676
+ }
+};
+is_deeply($module_data, $expected, "get_module_versions_in_release");
+
+done_testing();

0 comments on commit 55a1801

Please sign in to comment.
Something went wrong with that request. Please try again.