| 1 | # Copyright (c) 2024-2025 Philipp Schafft <lion@cpan.org> | ||
| 2 | |||
| 3 | # licensed under Artistic License 2.0 (see LICENSE file) | ||
| 4 | |||
| 5 | # ABSTRACT: generic module for extracting information from filesystems | ||
| 6 | |||
| 7 | |||
| 8 | package File::Information::VerifyResult; | ||
| 9 | |||
| 10 | use v5.10; | ||
| 11 | use strict; | ||
| 12 | use warnings; | ||
| 13 | |||
| 14 | use parent 'File::Information::VerifyBase'; | ||
| 15 | |||
| 16 | use Carp; | ||
| 17 | |||
| 18 | use File::Information::VerifyTestResult; | ||
| 19 | |||
| 20 | our $VERSION = v0.16; | ||
| 21 | |||
| 22 | # ---------------- | ||
| 23 | |||
| 24 | sub _new { | ||
| 25 | my ($pkg, %opts) = @_; | ||
| 26 | my $self = $pkg->SUPER::_new(%opts); | ||
| 27 | my %tests; | ||
| 28 | my $failed; | ||
| 29 | my %passed_by_class; | ||
| 30 | |||
| 31 | $self->{tests} = \%tests; | ||
| 32 | |||
| 33 | foreach my $name (File::Information::VerifyTestResult->_supported_tests) { | ||
| 34 | my $res = File::Information::VerifyTestResult->_new(test => $name, %opts{'instance', 'base', 'base_from', 'base_to', 'extractor', 'db', 'lifecycle_from', 'lifecycle_to'}); | ||
| 35 | my $class = $res->can('_class') ? $res->_class : $res->isa(__PACKAGE__) ? File::Information::VerifyTestResult->CLASS_STRONG : File::Information::VerifyTestResult->CLASS_WEAK; | ||
| 36 | $tests{$name} = $res; | ||
| 37 | |||
| 38 | $failed ||= $res->has_failed; | ||
| 39 | $passed_by_class{$class} ||= $res->has_passed; | ||
| 40 | } | ||
| 41 | |||
| 42 | if ($failed) { | ||
| 43 | $self->{status} = $pkg->STATUS_FAILED; | ||
| 44 | } elsif ($passed_by_class{File::Information::VerifyTestResult->CLASS_METADATA} && $passed_by_class{File::Information::VerifyTestResult->CLASS_STRONG}) { | ||
| 45 | $self->{status} = $pkg->STATUS_PASSED; | ||
| 46 | } elsif (scalar grep {$_} values %passed_by_class) { | ||
| 47 | $self->{status} = $pkg->STATUS_INSUFFICIENT_DATA; | ||
| 48 | } else { | ||
| 49 | $self->{status} = $pkg->STATUS_NO_DATA; | ||
| 50 | } | ||
| 51 | |||
| 52 | return $self; | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; | ||
| 56 | |||
| 57 | __END__ | ||
| 58 | |||
| 59 | =pod | ||
| 60 | |||
| 61 | =encoding UTF-8 | ||
| 62 | |||
| 63 | =head1 NAME | ||
| 64 | |||
| 65 | File::Information::VerifyResult - generic module for extracting information from filesystems | ||
| 66 | |||
| 67 | =head1 VERSION | ||
| 68 | |||
| 69 | version v0.16 | ||
| 70 | |||
| 71 | =head1 SYNOPSIS | ||
| 72 | |||
| 73 | use File::Information; | ||
| 74 | |||
| 75 | my File::Information::Inode $inode = ...; | ||
| 76 | |||
| 77 | my File::Information::VerifyResult $result = $inode->verify; | ||
| 78 | |||
| 79 | my $passed = $base->has_passed; | ||
| 80 | |||
| 81 | This package inherits from L<File::Information::VerifyBase>. | ||
| 82 | |||
| 83 | =head1 METHODS | ||
| 84 | |||
| 85 | =head1 AUTHOR | ||
| 86 | |||
| 87 | Philipp Schafft <lion@cpan.org> | ||
| 88 | |||
| 89 | =head1 COPYRIGHT AND LICENSE | ||
| 90 | |||
| 91 | This software is Copyright (c) 2024-2025 by Philipp Schafft <lion@cpan.org>. | ||
| 92 | |||
| 93 | This is free software, licensed under: | ||
| 94 | |||
| 95 | The Artistic License 2.0 (GPL Compatible) | ||
| 96 | |||
| 97 | =cut |