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   67871 use strict;
  3         18  
  3         99  
3 3     3   14 use warnings;
  3         4  
  3         110  
4 3     3   445 use CPAN::Audit::Version;
  3         6  
  3         1109  
5              
6             our $VERSION = "1.001";
7              
8             sub new {
9 1     1 0 1108 my($class, %params) = @_;
10 1   50     4 $params{db} ||= {};
11 1         2 my $self = bless {}, $class;
12 1         16 $self->{db} = $params{db};
13 1         6 return $self;
14             }
15              
16             =item * advisories_for( DISTNAME, VERSION_RANGE )
17              
18              
19             =cut
20              
21             sub advisories_for {
22 5     5 1 15 my( $self, $distname, $dist_version_range ) = @_;
23              
24 5 100 66     21 $dist_version_range = '>0' unless
25             defined $dist_version_range && 0 < length $dist_version_range;
26              
27 5         11 my $dist = $self->{db}->{dists}->{$distname};
28 5 100       30 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         23 my $affected = _includes( $_->{affected_versions}, $dist_version );
40 16         23 my $f = $_->{fixed_versions};
41 16 50 33     43 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         36 else { $affected }
46 8         10 } @{ $dist->{advisories} };
  8         16  
47             }
48 16         41 grep { CPAN::Audit::Version->in_range( $_, $dist_version_range ) }
49 16         27 map { $_->{version}}
50 4         8 @{ $dist->{versions} };
  4         8  
51              
52 4         21 values %advisories;
53             }
54              
55             sub _includes {
56 16     16   31 my( $range, $version ) = @_;
57 16         40 my $rc = CPAN::Audit::Version->in_range( $version, $range );
58             }
59              
60             1;