| 1 | package WARC::Index::Entries; # -*- CPerl -*- | ||||||||||
| 2 | |||||||||||
| 3 | 29 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 29 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 29 | require WARC::Index::Entry; | |||||||||
| 7 | 29 | our @ISA = qw(WARC::Index::Entry); | |||||||||
| 8 | |||||||||||
| 9 | 29 | require WARC; *WARC::Index::Entries::VERSION = \$WARC::VERSION; | |||||||||
| 10 | |||||||||||
| 11 | 29 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 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<WARC::Index::Entry/"Common Methods"> 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<WARC::Index::Entry> | ||||||||||
| 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 | ▶ | my $class = shift; | ||||||||
|
Subroutine
coalesce: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 52 | 110 | my $entries = shift; | |||||||||
| 53 | |||||||||||
| 54 | 110 | ▶ | return $entries->[0] if scalar @$entries == 1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | |||||||||||
| 56 | 1 | bless $entries, $class; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | =back | ||||||||||
| 60 | |||||||||||
| 61 | =cut | ||||||||||
| 62 | |||||||||||
| 63 | 1 | ▶ | sub index { croak "a coalesced index entry is not in any one index" } | ||||||||
|
Subroutine
index: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 64 | 1 | ▶ | sub volume { (shift)->[0]->volume } | ||||||||
|
Subroutine
volume: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 65 | 1 | ▶ | sub record { my $self = shift; $self->[0]->record(@_) } | ||||||||
|
Subroutine
record: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 66 | 1 | ▶ | sub record_offset { (shift)->[0]->record_offset } | ||||||||
|
Subroutine
record_offset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 67 | |||||||||||
| 68 | sub value { | ||||||||||
| 69 | 3 | ▶ | my $self = shift; | ||||||||
|
Subroutine
value: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 70 | 3 | my $key = shift; | |||||||||
| 71 | |||||||||||
| 72 | 3 | foreach my $entry (@$self) { | |||||||||
| 73 | 5 | my $v = $entry->value($key); | |||||||||
| 74 | 5 | ▶ | return $v if defined $v; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | # not found in any entry | ||||||||||
| 78 | 1 | return undef; | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | 29 | 1; | |||||||||
| 82 | __END__ | ||||||||||