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 29     29   69968 use strict;
  29         68  
  29         784  
4 29     29   132 use warnings;
  29         60  
  29         1806  
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 29     29   183 use Carp;
  29         64  
  29         7606  
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         125 my $entries = shift;
53              
54 110 100       366 return $entries->[0] if scalar @$entries == 1;
55              
56 1         10 bless $entries, $class;
57             }
58              
59             =back
60              
61             =cut
62              
63 1     1 1 201 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 544 sub record { my $self = shift; $self->[0]->record(@_) }
  1         5  
66 1     1 1 553 sub record_offset { (shift)->[0]->record_offset }
67              
68             sub value {
69 3     3 1 531 my $self = shift;
70 3         4 my $key = shift;
71              
72 3         7 foreach my $entry (@$self) {
73 5         12 my $v = $entry->value($key);
74 5 100       29 return $v if defined $v;
75             }
76              
77             # not found in any entry
78 1         5 return undef;
79             }
80              
81             1;
82             __END__