| 1 | package File::VirusScan; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use File::VirusScan::Result; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use File::VirusScan::ResultSet; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '0.105'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | # We don't use Module::Pluggable. Most users of this module will have | ||||||||||||||||||||||||||||
| 13 | # one or two virus scanners, with the other half-dozen or so plugins | ||||||||||||||||||||||||||||
| 14 | # going unused, so there's no sense in finding/loading all plugins. | ||||||||||||||||||||||||||||
| 15 | sub new | ||||||||||||||||||||||||||||
| 16 | 3 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 3 | my ($class, $conf) = @_; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | if(!exists $conf->{engines} || !scalar keys %{ $conf->{engines} }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $conf->{"engines"} and scalar keys %{$$conf{"engines"};}
MC/DC50%1/2
exists $conf->{"engines"} and scalar keys %{$$conf{"engines"};}
exists $conf->{"engines"}
scalar keys %{$$conf{"engines"};}
Truth table66%2/3
A and B
A= exists $conf->{"engines"}B= scalar keys %{$$conf{"engines"};}
| |||||||||||||||||||||||||||||
| 20 | 1 | croak q{Must supply an 'engines' value to constructor}; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | my %backends; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | # Load and initialise our backend engines | ||||||||||||||||||||||||||||
| 26 | 2 | ▶ | while (my ($moniker, $backend_conf) = each %{ $conf->{engines} }) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2 | $moniker =~ s/[^-A-Za-z0-9_:]//; | |||||||||||||||||||||||||||
| 29 | 2 | my $backclass = $moniker; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | substr($backclass, 0, 1, 'File::VirusScan::Engine::') if substr($backclass, 0, 1) eq '-'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | eval qq{use $backclass;}; ## no critic(StringyEval) | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 34 | 2 | ▶ | if($@) { ## no critic(PunctuationVars) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 1 | croak "Unable to find class $backclass for backend '$moniker'"; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 1 | $backends{$moniker} = $backclass->new($backend_conf); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 1 | my $self = { always_scan => $conf->{always_scan}, }; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 1 | ▶ | if(exists $conf->{order}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | $self->{_backends} = [ @backends{ @{ $conf->{order} } } ]; | |||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||
| 46 | 1 | $self->{_backends} = [ values %backends ]; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | return bless $self, $class; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | sub scan | ||||||||||||||||||||||||||||
| 53 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
scan: called CC=5 SCAR=17.6
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 2 | my ($self, $path) = @_; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 2 | my $result = File::VirusScan::ResultSet->new(); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | for my $back (@{ $self->{_backends} }) { | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | my $scan_result = eval { $back->scan($path) }; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | if($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | $result->add(File::VirusScan::Result->error("Error calling ->scan(): $@")); | |||||||||||||||||||||||||||
| 64 | } else { | ||||||||||||||||||||||||||||
| 65 | 2 | $result->add($scan_result); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | ▶ | if(!$self->{always_scan} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $self->{"always_scan"} and $result->has_virus
MC/DC0%0/2
not $self->{"always_scan"} and $result->has_virus
not $self->{"always_scan"}
$result->has_virus
Truth table33%1/3
not(A) and B
A= not $self->{"always_scan"}B= $result->has_virus
| |||||||||||||||||||||||||||||
| 69 | && $result->has_virus()) | ||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 0 | last; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | return $result; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | sub get_backends | ||||||||||||||||||||||||||||
| 79 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_backends: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 81 | 0 | return $self->{_backends}; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | 1; | |||||||||||||||||||||||||||
| 85 | __END__ | ||||||||||||||||||||||||||||