File Coverage

lib/CPAN/Audit/Query.pm
Criterion Covered Total %
statement 33 35 94.2
branch 5 8 62.5
condition 5 11 45.4
subroutine 6 6 100.0
pod 1 2 50.0
total 50 62 80.6


line stmt bran cond sub pod time code
1             package CPAN::Audit::Query;
2 3     3   67551 use strict;
  3         14  
  3         93  
3 3     3   14 use warnings;
  3         6  
  3         70  
4 3     3   428 use CPAN::Audit::Version;
  3         8  
  3         1085  
5              
6             our $VERSION = "1.001";
7              
8             sub new {
9 1     1 0 1067 my($class, %params) = @_;
10 1   50     5 $params{db} ||= {};
11 1         3 my $self = bless {}, $class;
12 1         5 $self->{db} = $params{db};
13 1         3 return $self;
14             }
15              
16             =item * advisories_for( DISTNAME, VERSION_RANGE )
17              
18              
19             =cut
20              
21             sub advisories_for {
22 5     5 1 20 my( $self, $distname, $dist_version_range ) = @_;
23              
24 5 100 66     24 $dist_version_range = '>0' unless
25             defined $dist_version_range && 0 < length $dist_version_range;
26              
27 5         9 my $dist = $self->{db}->{dists}->{$distname};
28 5 100       37 return unless $dist;
29              
30             # select only the known distribution versions from the database,
31             # ignoring all others. For example, if $dist_version_range is
32             # ">5.1", we don't care about any versions less than or equal to 5.1.
33             # If $dist_version_range is "5.1", that really means ">=5.1"
34             my %advisories =
35 4         10 map { $_->{id}, $_ }
36             map {
37 8         14 my $dist_version = $_;
38             grep {
39 16         27 my $affected = _includes( $_->{affected_versions}, $dist_version );
40 16         37 my $f = $_->{fixed_versions};
41 16 50 33     42 if( exists $_->{fixed_versions} and defined $f and length $f ) {
      33        
42 0         0 my $fixed = _includes( $f, $dist_version );
43 0 0       0 $fixed ? 0 : $affected
44             }
45 16         37 else { $affected }
46 8         9 } @{ $dist->{advisories} };
  8         14  
47             }
48 16         40 grep { CPAN::Audit::Version->in_range( $_, $dist_version_range ) }
49 16         30 map { $_->{version}}
50 4         8 @{ $dist->{versions} };
  4         9  
51              
52 4         24 values %advisories;
53             }
54              
55             sub _includes {
56 16     16   26 my( $range, $version ) = @_;
57 16         35 my $rc = CPAN::Audit::Version->in_range( $version, $range );
58             }
59              
60             1;