File Coverage

blib/lib/WARC/Index/Entries.pm
Criterion Covered Total %
statement 24 24 100.0
branch 4 4 100.0
condition n/a
subroutine 9 9 100.0
pod 6 6 100.0
total 43 43 100.0


line stmt bran cond sub pod time code
1             package WARC::Index::Entries; # -*- CPerl -*-
2              
3 27     27   70661 use strict;
  27         62  
  27         817  
4 27     27   146 use warnings;
  27         69  
  27         1780  
5              
6             require WARC::Index::Entry;
7             our @ISA = qw(WARC::Index::Entry);
8              
9             require WARC; *WARC::Index::Entries::VERSION = \$WARC::VERSION;
10              
11 27     27   196 use Carp;
  27         48  
  27         7502  
12              
13             =head1 NAME
14              
15             WARC::Index::Entries - combine information from multiple WARC::Index entries
16              
17             =head1 SYNOPSIS
18              
19             use WARC::Collection;
20              
21             # WARC::Index::Entries objects are used to merge data from multiple indexes
22             # and are used internally when searching a collection with multiple indexes
23              
24             =cut
25              
26             # This implementation uses an array of index entries as the underlying
27             # structure. Correct results depend on all entries in the array referring
28             # to the same record.
29              
30             =head1 DESCRIPTION
31              
32             See L for accessor methods.
33              
34             =head2 Constructor
35              
36             =over
37              
38             =item $combined_entry = coalesce WARC::Index::Entries ( [ ... ] )
39              
40             Return a coalesced index entry by combining multiple C
41             objects, presumably from different indexes. All of the index entries so
42             combined must have the same tag value, or the resultant behavior is
43             undefined. This constructor does not verify this requirement.
44              
45             Since this is intended for internal use, the array reference passed to the
46             constructor is reused as part of the returned object.
47              
48             =cut
49              
50             sub coalesce {
51 110     110 1 788 my $class = shift;
52 110         144 my $entries = shift;
53              
54 110 100       370 return $entries->[0] if scalar @$entries == 1;
55              
56 1         22 bless $entries, $class;
57             }
58              
59             =back
60              
61             =cut
62              
63 1     1 1 212 sub index { croak "a coalesced index entry is not in any one index" }
64 1     1 1 391 sub volume { (shift)->[0]->volume }
65 1     1 1 530 sub record { my $self = shift; $self->[0]->record(@_) }
  1         6  
66 1     1 1 561 sub record_offset { (shift)->[0]->record_offset }
67              
68             sub value {
69 3     3 1 534 my $self = shift;
70 3         5 my $key = shift;
71              
72 3         8 foreach my $entry (@$self) {
73 5         13 my $v = $entry->value($key);
74 5 100       27 return $v if defined $v;
75             }
76              
77             # not found in any entry
78 1         5 return undef;
79             }
80              
81             1;
82             __END__