File Coverage

blib/lib/App/UpdateCPANfile/PackageDetails.pm
Criterion Covered Total %
statement 33 34 97.0
branch 3 4 75.0
condition n/a
subroutine 9 10 90.0
pod 0 5 0.0
total 45 53 84.9


line stmt bran cond sub pod time code
1             package App::UpdateCPANfile::PackageDetails;
2 2     2   232118 use strict;
  2         9  
  2         70  
3 2     2   11 use warnings;
  2         4  
  2         66  
4              
5 2     2   1074 use CPAN::PackageDetails;
  2         25649  
  2         67  
6 2     2   1428 use LWP::UserAgent;
  2         84204  
  2         78  
7 2     2   1057 use IO::String;
  2         7896  
  2         533  
8              
9             sub new {
10 9     9 0 19163 my ($class) = @_;
11              
12 9         67 bless {}, $class;
13             }
14              
15             # Parsing detail is heavy operation.
16             my $details_cache;
17              
18             sub details {
19 31     31 0 674 my ($self) = @_;
20 31 100       269 if ($details_cache) {
21 29         239 return $details_cache;
22             }
23              
24 2         38 my $agent = LWP::UserAgent->new(
25             agent => 'UpdateCPANfile/0.1',
26             timeout => 60,
27             );
28              
29 2         5906 my $file = IO::String->new;
30 2         155 my $res = $agent->get('http://www.cpan.org/modules/02packages.details.txt.gz');
31 2         47595 $file->print($res->content);
32 2         15932 $file->setpos(0);
33              
34 2         70 $details_cache = CPAN::PackageDetails->read( $file );
35             }
36              
37             sub clear_details_cache {
38 0     0 0 0 $details_cache = undef;
39             }
40              
41             sub package_object {
42 30     30 0 46966422 my ($self, $package) = @_;
43 30         170 my ($package_object) = $self->details->entries->get_entries_by_package($package);
44 30         59606363 $package_object;
45             }
46              
47             sub latest_version_for_package {
48 2     2 0 4263 my ($self, $package) = @_;
49 2         25 my $package_object = $self->package_object($package);
50 2 50       40 return undef unless $package_object;
51 2         27 return $package_object->version;
52             }
53              
54             1;