File Coverage

lib/File/Information/VerifyBase.pm
Criterion Covered Total %
statement 14 48 29.1
branch 0 10 0.0
condition 0 22 0.0
subroutine 5 18 27.7
pod 12 12 100.0
total 31 110 28.1


line stmt bran cond sub pod time code
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::VerifyBase;
9              
10 1     1   4099 use v5.10;
  1         3  
11 1     1   5 use strict;
  1         3  
  1         20  
12 1     1   3 use warnings;
  1         1  
  1         64  
13              
14 1     1   6 use Carp;
  1         2  
  1         112  
15              
16             our $VERSION = v0.16;
17              
18             use constant {
19 1         971 STATUS_ERROR => 'error',
20             STATUS_PASSED => 'passed',
21             STATUS_FAILED => 'failed',
22             STATUS_NO_DATA => 'no_data',
23             STATUS_INSUFFICIENT_DATA => 'insufficient_data',
24 1     1   5 };
  1         1  
25              
26              
27             sub status {
28 0     0 1   my ($self) = @_;
29 0           return $self->{status};
30             }
31              
32              
33             sub has_error {
34 0     0 1   my ($self) = @_;
35 0           return $self->{status} eq STATUS_ERROR;
36             }
37              
38              
39             sub has_passed {
40 0     0 1   my ($self) = @_;
41 0           return $self->{status} eq STATUS_PASSED;
42             }
43              
44              
45             sub has_failed {
46 0     0 1   my ($self) = @_;
47 0           return $self->{status} eq STATUS_FAILED;
48             }
49              
50              
51             sub has_no_data {
52 0     0 1   my ($self) = @_;
53 0           return $self->{status} eq STATUS_NO_DATA;
54             }
55              
56              
57             sub has_insufficient_data {
58 0     0 1   my ($self) = @_;
59 0           return $self->{status} eq STATUS_INSUFFICIENT_DATA;
60             }
61              
62              
63             #@returns File::Information::Base
64             sub base {
65 0     0 1   my ($self) = @_;
66 0           return $self->{base};
67             }
68              
69              
70             #@returns File::Information::Base
71             sub base_from {
72 0     0 1   my ($self) = @_;
73 0   0       return $self->{base_from} // $self->{base};
74             }
75              
76              
77             #@returns File::Information::Base
78             sub base_to {
79 0     0 1   my ($self) = @_;
80 0   0       return $self->{base_to} // $self->{base};
81             }
82              
83              
84             #@returns File::Information
85             sub instance {
86 0     0 1   my ($self) = @_;
87 0           return $self->{instance};
88             }
89              
90              
91             #@returns Data::URIID
92             sub extractor {
93 0     0 1   my ($self, @args) = @_;
94 0   0       return $self->{extractor} //= $self->instance->extractor(@args);
95             }
96              
97             #@returns Data::TagDB
98             sub db {
99 0     0 1   my ($self, @args) = @_;
100 0   0       return $self->{db} //= $self->instance->db(@args);
101             }
102              
103             # ----------------
104              
105             sub _new {
106 0     0     my ($pkg, %opts) = @_;
107 0           my $self = bless(\%opts, $pkg);
108              
109 0   0       $self->{lifecycle_from} //= 'current';
110 0   0       $self->{lifecycle_to} //= 'final';
111              
112 0 0         croak 'No instance is given' unless defined $self->{instance};
113 0 0 0       croak 'No base_from is given' unless defined($self->{base_from}) || defined($self->{base});
114 0 0 0       croak 'No base_to is given' unless defined($self->{base_to}) || defined($self->{base});
115 0 0         croak 'No lifecycle_from is given' unless defined $self->{lifecycle_from};
116 0 0         croak 'No lifecycle_to is given' unless defined $self->{lifecycle_to};
117              
118 0           return $self;
119             }
120              
121             1;
122              
123             __END__
124              
125             =pod
126              
127             =encoding UTF-8
128              
129             =head1 NAME
130              
131             File::Information::VerifyBase - generic module for extracting information from filesystems
132              
133             =head1 VERSION
134              
135             version v0.16
136              
137             =head1 SYNOPSIS
138              
139             use File::Information;
140              
141             my File::Information::VerifyBase $base = ...;
142              
143             my $passed = $base->is_passed;
144              
145             This package contains the basic methods for verify results.
146             See also L<File::Information::Base/verify>.
147              
148             =head1 METHODS
149              
150             =head2 status
151              
152             my $status = $obj->status;
153              
154             Returns the status of the test.
155             Most commonly one want to check for the passed state using L</has_passed>.
156              
157             =head2 has_error
158              
159             my $has_error = $obj->has_error;
160              
161             Returns if the status is the error status. That is the test was not performed
162             (likely due to an internal error or an operating system error).
163              
164             B<Note:>
165             This is B<not> the opposite of L</has_passed>.
166              
167             =head2 has_passed
168              
169             my $has_passed = $obj->has_passed;
170              
171             This will return if the test was successfully passed.
172             That is the data is available and matched the expected value.
173              
174             B<Note:>
175             This is B<not> the opposite of L</has_failed> or L</has_error>.
176              
177             =head2 has_failed
178              
179             my $has_failed = $obj->has_failed;
180              
181             Returns if the status is the failed status.
182             That is the test was successfully performed but the data did not match.
183              
184             B<Note:>
185             This is B<not> the opposite of L</has_passed>.
186              
187             =head2 has_no_data
188              
189             my $has_no_data = $obj->has_no_data;
190              
191             Returns true if the test was not performed due to missing data.
192              
193             =head2 has_insufficient_data
194              
195             my $has_insufficient_data = $obj->has_insufficient_data;
196              
197             Returnes true if the test was performed but there is data missing for it to pass.
198             The parts that have been performed did not fail.
199              
200             =head2 base
201              
202             my File::Information::Base $base = $obj->base;
203              
204             Returns the base that was used to create this object.
205              
206             B<Note:>
207             This method is deprecated and will be removed in future versions.
208              
209             See also
210             L</base_from>,
211             L</base_to>.
212              
213             =head2 base_from
214              
215             my File::Information::Base $base = $obj->base_from;
216              
217             Returns the base object used for the I<from> side of the verify.
218              
219             See also
220             L</base_to>.
221              
222             =head2 base_to
223              
224             my File::Information::Base $base = $obj->base_from;
225              
226             Returns the base object used for the I<to> side of the verify.
227              
228             See also
229             L</base_from>.
230              
231             =head2 instance
232              
233             my File::Information $instance = $obj->instance;
234              
235             Returns the instance that was used to create this object.
236              
237             =head2 extractor, db
238              
239             my Data::URIID $extractor = $obj->extractor;
240             my Data::TagDB $db = $obj->db;
241             my ... = $obj->digest_info;
242              
243             These methods provide access to the same data as the methods of L<File::Information>.
244             Arguments will be passed to said functions. However the object my cache the result.
245             Therefore it is only allowed to pass arguments that are compatible with caching (if any exist).
246              
247             See L<File::Information/extractor>, and L<File::Information/db> for details.
248              
249             =head1 AUTHOR
250              
251             Philipp Schafft <lion@cpan.org>
252              
253             =head1 COPYRIGHT AND LICENSE
254              
255             This software is Copyright (c) 2024-2025 by Philipp Schafft <lion@cpan.org>.
256              
257             This is free software, licensed under:
258              
259             The Artistic License 2.0 (GPL Compatible)
260              
261             =cut