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