| 1 | 14 | ▶ | use v5.10; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 2 | |||||||||||||
| 3 | package CPAN::Audit::Filter; | ||||||||||||
| 4 | 14 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 14 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 14 | our $VERSION = "1.001"; | |||||||||||
| 8 | |||||||||||||
| 9 | =encoding utf8 | ||||||||||||
| 10 | |||||||||||||
| 11 | =head1 NAME | ||||||||||||
| 12 | |||||||||||||
| 13 | CPAN::Audit::Filter - manage the reports / CVEs to ignore | ||||||||||||
| 14 | |||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||
| 16 | |||||||||||||
| 17 | use CPAN::Audit::Filter; | ||||||||||||
| 18 | |||||||||||||
| 19 | my $filter = CPAN::Audit::Filter->new( exclude => $array_ref ); | ||||||||||||
| 20 | |||||||||||||
| 21 | my $query = CPAN::Audit::Query->new(...); | ||||||||||||
| 22 | my $advisories = $query->advisories_for( $distname, $version_range ); | ||||||||||||
| 23 | |||||||||||||
| 24 | foreach my $advisory ( $advisories->@* ) { | ||||||||||||
| 25 | next if $filter->excludes($advisory); | ||||||||||||
| 26 | ... | ||||||||||||
| 27 | } | ||||||||||||
| 28 | |||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||
| 30 | |||||||||||||
| 31 | =head2 Class methods | ||||||||||||
| 32 | |||||||||||||
| 33 | =over 4 | ||||||||||||
| 34 | |||||||||||||
| 35 | =item * new( exclude => ARRAYREF ) | ||||||||||||
| 36 | |||||||||||||
| 37 | The values in the array ref for C<exclude> are uppercased before | ||||||||||||
| 38 | they are stored. | ||||||||||||
| 39 | |||||||||||||
| 40 | =cut | ||||||||||||
| 41 | |||||||||||||
| 42 | 11 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 43 | 11 | my($class, %params) = @_; | |||||||||||
| 44 | |||||||||||||
| 45 | 11 | my $self = bless {}, $class; | |||||||||||
| 46 | 11 | ▶ | $params{exclude} //= []; | ||||||||||
|
Condition100%2/2
$params{"exclude"} //= []
MC/DC100%1/1
$params{"exclude"} //= []
$params{"exclude"}
Truth table100%2/2
A
A= $params{"exclude"}
| |||||||||||||
| 47 | |||||||||||||
| 48 | 11 | my %excludes = map { uc($_) => 1 } @{ $params{exclude} }; | |||||||||||
| 49 | 11 | $self->{excludes} = \%excludes; | |||||||||||
| 50 | |||||||||||||
| 51 | 11 | $self->{ignored} = {}; | |||||||||||
| 52 | |||||||||||||
| 53 | 11 | return $self; | |||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | |||||||||||||
| 57 | =back | ||||||||||||
| 58 | |||||||||||||
| 59 | =head2 Instance methods | ||||||||||||
| 60 | |||||||||||||
| 61 | =over 4 | ||||||||||||
| 62 | |||||||||||||
| 63 | =item * excludes( $advisory ) | ||||||||||||
| 64 | |||||||||||||
| 65 | Returns true if this instance excludes either the ID or any of the | ||||||||||||
| 66 | CVEs for ADVISORY, a hash as returned by L<CPAN::Audit::Query>. This | ||||||||||||
| 67 | hash has these keys: | ||||||||||||
| 68 | |||||||||||||
| 69 | id - a string, such as Some-Module-001 | ||||||||||||
| 70 | cves - an array reference of CVE strings, such as CVE-2022-001 | ||||||||||||
| 71 | |||||||||||||
| 72 | The values extracted from the hash are uppercased before use. | ||||||||||||
| 73 | |||||||||||||
| 74 | =cut | ||||||||||||
| 75 | |||||||||||||
| 76 | 81 | ▶ | sub excludes { | ||||||||||
|
Subroutine
excludes: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 77 | 81 | my($self, $advisory) = @_; | |||||||||||
| 78 | |||||||||||||
| 79 | 81 | ▶ | return 0 unless keys %{$self->{excludes}}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 80 | |||||||||||||
| 81 | 2 | my @ids = map { uc } grep { defined } ($advisory->{id}, @{$advisory->{cves}}); | |||||||||||
| 82 | |||||||||||||
| 83 | 2 | foreach my $id ( @ids ) { | |||||||||||
| 84 | 2 | ▶ | next unless $self->{excludes}{$id}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 85 | 1 | $self->{ignored}{$id}++; | |||||||||||
| 86 | 1 | return 1; | |||||||||||
| 87 | } | ||||||||||||
| 88 | |||||||||||||
| 89 | 1 | return 0; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | =item * ignored_count | ||||||||||||
| 93 | |||||||||||||
| 94 | Return the count of the advisories that were ignored. Each ID or CVE | ||||||||||||
| 95 | value only counts once. | ||||||||||||
| 96 | |||||||||||||
| 97 | =cut | ||||||||||||
| 98 | |||||||||||||
| 99 | 2 | ▶ | sub ignored_count { scalar keys %{$_[0]->{ignored}} } | ||||||||||
|
Subroutine
ignored_count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 100 | |||||||||||||
| 101 | =back | ||||||||||||
| 102 | |||||||||||||
| 103 | =head1 LICENSE | ||||||||||||
| 104 | |||||||||||||
| 105 | Copyright (C) 2022 Graham TerMarsch | ||||||||||||
| 106 | |||||||||||||
| 107 | This library is free software; you can redistribute it and/or modify | ||||||||||||
| 108 | it under the same terms as Perl itself. | ||||||||||||
| 109 | |||||||||||||
| 110 | =cut | ||||||||||||
| 111 | |||||||||||||
| 112 | 14 | 1; | |||||||||||