lib/CPAN/Audit/Query.pm

filter: Statementstmt 100% 44 / 44 Branchbran 100% 10 / 10 Conditioncond 72.7% 8 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 92.5% 74 / 80 CC 11 SCAR 15.6
CC
11
Cov
95%
advisories_for
8.0
_includes
3.0
new
2.0
CRAP 4.8
« blib/lib/CPAN/Audit/Installed.pm ↑ Summary lib/CPAN/Audit/Version.pm »
1 package CPAN::Audit::Query;
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use CPAN::Audit::Version;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 14 our $VERSION = "1.003";
7  
8 =encoding utf8
9  
10 =head1 NAME
11  
12 CPAN::Audit::Query - filter the database for advisories that interest you
13  
14 =head1 SYNOPSIS
15  
16 use CPAN::Audit::Query;
17  
18 my $query = CPAN::Audit::Query->new( db => ... );
19 my @advisories = $query->advisories_for( $dist_name, $version_range );
20  
21 =head1 DESCRIPTION
22  
23 =head2 Class methods
24  
25 =over 4
26  
27 =item * new(HASH)
28  
29 The only parameter is the hash reference from L<CPAN::Audit::DB> (deprecated) or
30 L<CPANSA::DB>. With no C<db> parameter, it uses the empty hash,
31 which means that you'll find no advisories.
32  
33 =cut
34  
35 9 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
36 9 my($class, %params) = @_;
37 9 ▶ $params{db} ||= {};
Condition50%1/2
$params{"db"} ||= {}
l!l
90
MC/DC0%0/1
$params{"db"} ||= {}
$params{"db"}
Truth table50%1/2
A
A= $params{"db"}
Aresult
11
00
38 9 my $self = bless {}, $class;
39 9 $self->{db} = $params{db};
40 9 return $self;
41 }
42  
43 =back
44  
45 =head2 Instance methods
46  
47 =over 4
48  
49 =item * advisories_for( DISTNAME, VERSION_RANGE )
50  
51 Returns a list of advisories for DISTNAME in VERSION_RANGE.
52  
53 my @advisories = $query->advisories_for( 'Business-ISBN', '1.23' );
54  
55 my @advisories = $query->advisories_for( 'Business-ISBN', '>1.23,<2.45' );
56  
57 my @advisories = $query->advisories_for( 'Business-ISBN', '<1.23' );
58  
59 =cut
60  
61 175 ▶sub advisories_for {
Subroutine advisories_for: called CC=8 SCAR=20.8
Pod documented
62 175 my( $self, $distname, $dist_version_range ) = @_;
63  
64 175 ▶ $dist_version_range = '>0' unless
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dist_version_range and 0 < length $dist_version_range 6 169 175
Condition100%3/3
defined $dist_version_range and 0 < length $dist_version_range
!ll&&!rl&&r
24169
MC/DC100%2/2
defined $dist_version_range and 0 < length $dist_version_range
defined $dist_version_range 0 < length $dist_version_range
Truth table100%3/3
A and B
A= defined $dist_version_rangeB= 0 < length $dist_version_range
ABresult
0X0
100
111
65 defined $dist_version_range && 0 < length $dist_version_range;
66  
67 175 my $dist = $self->{db}->{dists}->{$distname};
68 175 ▶ return unless $dist;
Branch: 1 branch
BranchTrueFalseTotal
unless $dist 1 174 175
69  
70 # select only the known distribution versions from the database,
71 # ignoring all others. For example, if $dist_version_range is
72 # ">5.1", we don't care about any versions less than or equal to 5.1.
73 # If $dist_version_range is "5.1", that really means ">=5.1"
74 my %advisories =
75 28401 map { $_->{id}, $_ }
76 map {
77 3456 my $dist_version = $_;
78 grep {
79 51181 my $affected = _includes( $_->{affected_versions}, $dist_version );
80 51181 my $f = $_->{fixed_versions};
81 51181 ▶ if( exists $_->{fixed_versions} and defined $f and length $f ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $_->{'fixed_versions'} and defined $f and length $f) { } 51165 16 51181
Condition66%4/6
exists $_->{"fixed_versions"} and defined $f and length $f
!ll&&!rl&&r
16051165
exists $_->{"fixed_versions"} and defined $f
!ll&&!rl&&r
16051165
MC/DC33%1/3
exists $_->{"fixed_versions"} and defined $f and length $f
exists $_->{"fixed_versions"} defined $f length $f
Truth table50%2/4
A and B and C
A= exists $_->{"fixed_versions"}B= defined $fC= length $f
ABCresult
0XX0
10X0
1100
1111
82 51165 my $fixed = _includes( $f, $dist_version );
83 51165 ▶ $fixed ? 0 : $affected
Branch: 1 branch
BranchTrueFalseTotal
$fixed ? : 17653 33512 51165
84 }
85 16 else { $affected }
86 3456 } @{ $dist->{advisories} };
87 }
88 21762 grep { CPAN::Audit::Version->in_range( $_, $dist_version_range ) }
89 21762 map { $_->{version} }
90 174 @{ $dist->{versions} };
91  
92 174 values %advisories;
93 }
94  
95 102346 ▶sub _includes {
Subroutine _includes: called CC=3 SCAR=11.0
96 102346 my( $range, $version ) = @_;
97 102346 ▶ $range = [$range] unless ref $range;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $range 16 102330 102346
98 102346 my $rc = 0;
99 102346 foreach my $r ( @$range ) {
100 14 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
101 98126 $rc += CPAN::Audit::Version->in_range( $version, $r );
102 }
103 102346 return $rc;
104 }
105  
106 =back
107  
108 =head1 LICENSE
109  
110 Copyright (C) Viacheslav Tykhanovskyi.
111  
112 This library is free software; you can redistribute it and/or modify
113 it under the same terms as Perl itself.
114  
115 =head1 AUTHOR
116  
117 Viacheslav Tykhanovskyi E<lt>viacheslav.t@gmail.comE<gt>
118  
119 =cut
120  
121 14 1;
« blib/lib/CPAN/Audit/Installed.pm ↑ Summary lib/CPAN/Audit/Version.pm »