File Coverage

blib/lib/Catmandu/Fix/Condition/is_archived_web_uri.pm
Criterion Covered Total %
statement 19 19 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 6 6 100.0
pod 0 1 0.0
total 27 31 87.1


line stmt bran cond sub pod time code
1             package Catmandu::Fix::Condition::is_archived_web_uri;
2              
3             our $VERSION = '0.14';
4              
5 1     1   520749 use Catmandu::Sane;
  1         10  
  1         10  
6 1     1   233 use Moo;
  1         2  
  1         9  
7 1     1   936 use Data::Validate::URI;
  1         47273  
  1         66  
8 1     1   527 use Memento::TimeTravel;
  1         5  
  1         42  
9 1     1   8 use Catmandu::Fix::Has;
  1         3  
  1         14  
10              
11             has path => (fix_arg => 1);
12             has date => (fix_arg => 1);
13              
14             with 'Catmandu::Fix::Condition::SimpleAllTest';
15              
16             sub emit_test {
17 5     5 0 27858 my ($self, $var) = @_;
18 5         19 my $date = $self->date;
19 5 50 33     31 $date = [localtime]->[5] + 1900 unless defined($date) && length($date);
20              
21 5         30 "(is_value(${var}) && Data::Validate::URI::is_web_uri(${var}) && Memento::TimeTravel::find_mementos(${var},${date}))";
22             }
23              
24             =head1 NAME
25              
26             Catmandu::Fix::Condition::is_archived_web_uri - check of a field contains an HTTP or HTTPS URI which is archived in a web archive
27              
28             =head1 SYNOPSIS
29              
30             # Check if an archived version is available for any year...
31             if is_archived_web_uri(uri_field,'')
32             ...
33             else
34             ...
35             end
36              
37             # Check if an archived version is available for a year...
38             if is_archived_web_uri(uri_field,2013)
39             ...
40             else
41             ...
42             end
43              
44             =head1 SEE ALSO
45              
46             L<Catmandu::Fix>
47              
48             =cut
49              
50             1;