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   66910 use strict;
  27         66  
  27         745  
4 27     27   124 use warnings;
  27         48  
  27         1748  
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   162 use Carp;
  27         61  
  27         7115  
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 728 my $class = shift;
52 110         129 my $entries = shift;
53              
54 110 100       363 return $entries->[0] if scalar @$entries == 1;
55              
56 1         8 bless $entries, $class;
57             }
58              
59             =back
60              
61             =cut
62              
63 1     1 1 204 sub index { croak "a coalesced index entry is not in any one index" }
64 1     1 1 387 sub volume { (shift)->[0]->volume }
65 1     1 1 542 sub record { my $self = shift; $self->[0]->record(@_) }
  1         4  
66 1     1 1 600 sub record_offset { (shift)->[0]->record_offset }
67              
68             sub value {
69 3     3 1 533 my $self = shift;
70 3         6 my $key = shift;
71              
72 3         6 foreach my $entry (@$self) {
73 5         10 my $v = $entry->value($key);
74 5 100       31 return $v if defined $v;
75             }
76              
77             # not found in any entry
78 1         4 return undef;
79             }
80              
81             1;
82             __END__