| 1 | package WARC::Index::Builder; # -*- CPerl -*- | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 5 | our @ISA = qw(); | |||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | 5 | require WARC; *WARC::Index::Builder::VERSION = \$WARC::VERSION; | |||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 5 | ▶ | use Carp; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | WARC::Index::Builder - abstract base class for building indexes | ||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | use WARC::Index; | ||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | $cdx_builder = build WARC::Index::File::CDX (...); | ||||||||||||||||||||||
| 21 | $sdbm_builder = build WARC::Index::File::SDBM (...); | ||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | $cdx_entry = $cdx_builder->add($record); | ||||||||||||||||||||||
| 24 | $sdbm_builder->add($cdx_entry); | ||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | C<WARC::Index::Builder> is an abstract base class for constructing indexes | ||||||||||||||||||||||
| 29 | on WARC files. The interface is documented here, but implemented in | ||||||||||||||||||||||
| 30 | specialized classes for each index type. Some common code has also been | ||||||||||||||||||||||
| 31 | moved to this class, and is also documented here. | ||||||||||||||||||||||
| 32 | |||||||||||||||||||||||
| 33 | =head2 Methods | ||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | =over | ||||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | =item $builder-E<gt>add( ... ) | ||||||||||||||||||||||
| 38 | |||||||||||||||||||||||
| 39 | Add items to the growing index. All index types accept both WARC records | ||||||||||||||||||||||
| 40 | and entries from other indexes, although only metaindex-capable formats use | ||||||||||||||||||||||
| 41 | the latter. Any number of items may be added with a single call. | ||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | Returns nothing. | ||||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | The C<WARC::Index::Builder> base class provides an implementation of this | ||||||||||||||||||||||
| 46 | method that dispatches to the internal _add_* methods listed below. | ||||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | =cut | ||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | sub add { | ||||||||||||||||||||||
| 51 | 27 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
add: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | 27 | foreach (@_) { | |||||||||||||||||||||
| 54 | 27 | ▶ | if (not ref) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 55 | # treat a loose scalar as a WARC volume file name | ||||||||||||||||||||||
| 56 | 15 | { $self->_add_volume(mount WARC::Volume ($_)) } | |||||||||||||||||||||
| 57 | else { | ||||||||||||||||||||||
| 58 | 12 | ▶ | if ($_->isa('WARC::Volume')) { $self->_add_volume($_) } | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 59 | 3 | elsif($_->isa('WARC::Index')) { $self->_add_index($_) } | |||||||||||||||||||||
| 60 | 2 | elsif($_->isa('WARC::Index::Entry')) { $self->_add_entry($_) } | |||||||||||||||||||||
| 61 | 2 | elsif($_->isa('WARC::Record::FromVolume')){ $self->_add_record($_) } | |||||||||||||||||||||
| 62 | 2 | else { croak "unrecognized object $_" } | |||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||
| 66 | |||||||||||||||||||||||
| 67 | =item $builder-E<gt>flush | ||||||||||||||||||||||
| 68 | |||||||||||||||||||||||
| 69 | Write any buffered data to the underlying storage. After calling this | ||||||||||||||||||||||
| 70 | method, all records added using this builder should be visible. Some index | ||||||||||||||||||||||
| 71 | systems do this implicitly; this method is a no-op in those cases. | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | Returns nothing. | ||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||||
| 76 | |||||||||||||||||||||||
| 77 | ▶ | sub flush {} | |||||||||||||||||||||
|
Subroutine
flush: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | =back | ||||||||||||||||||||||
| 80 | |||||||||||||||||||||||
| 81 | =head2 Internal Methods | ||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | =over | ||||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | =item $builder-E<gt>_add_record( $record ) | ||||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | Add one L<WARC::Record> to the index. | ||||||||||||||||||||||
| 88 | |||||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | =item $builder-E<gt>_add_entry( $entry ) | ||||||||||||||||||||||
| 92 | |||||||||||||||||||||||
| 93 | Add one L<WARC::Index::Entry> to the index. | ||||||||||||||||||||||
| 94 | |||||||||||||||||||||||
| 95 | The C<WARC::Index::Builder> base class provides a default implementation | ||||||||||||||||||||||
| 96 | that adds the corresponding record instead. | ||||||||||||||||||||||
| 97 | |||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | sub _add_entry { | ||||||||||||||||||||||
| 101 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
_add_entry: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 102 | 5 | my $source = shift; | |||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | 5 | $self->_add_record($source->record); | |||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||
| 106 | |||||||||||||||||||||||
| 107 | =item $builder-E<gt>_add_index( $index ) | ||||||||||||||||||||||
| 108 | |||||||||||||||||||||||
| 109 | Add all entries from an enumerable index to the index. | ||||||||||||||||||||||
| 110 | |||||||||||||||||||||||
| 111 | The C<WARC::Index::Builder> base class provides a default implementation. | ||||||||||||||||||||||
| 112 | |||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||
| 114 | |||||||||||||||||||||||
| 115 | sub _add_index { | ||||||||||||||||||||||
| 116 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
_add_index: called CC=2 SCAR=6.9
| |||||||||||||||||||||||
| 117 | 3 | my $source = shift; | |||||||||||||||||||||
| 118 | |||||||||||||||||||||||
| 119 | 3 | ▶ | for (my $entry = $source->first_entry; $entry; $entry = $entry->next) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 120 | 54 | { $self->_add_entry($entry) } | |||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||
| 122 | |||||||||||||||||||||||
| 123 | =item $builder-E<gt>_add_volume( $volume ) | ||||||||||||||||||||||
| 124 | |||||||||||||||||||||||
| 125 | Add all records from a L<WARC::Volume> to the index. | ||||||||||||||||||||||
| 126 | |||||||||||||||||||||||
| 127 | The C<WARC::Index::Builder> base class provides a default implementation. | ||||||||||||||||||||||
| 128 | |||||||||||||||||||||||
| 129 | =cut | ||||||||||||||||||||||
| 130 | |||||||||||||||||||||||
| 131 | sub _add_volume { | ||||||||||||||||||||||
| 132 | 18 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
_add_volume: called CC=2 SCAR=6.9
| |||||||||||||||||||||||
| 133 | 18 | my $volume = shift; | |||||||||||||||||||||
| 134 | |||||||||||||||||||||||
| 135 | 18 | ▶ | for (my $record = $volume->first_record; $record; $record = $record->next) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 136 | 237 | { $self->_add_record($record) } | |||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||
| 138 | |||||||||||||||||||||||
| 139 | =back | ||||||||||||||||||||||
| 140 | |||||||||||||||||||||||
| 141 | =cut | ||||||||||||||||||||||
| 142 | |||||||||||||||||||||||
| 143 | 5 | 1; | |||||||||||||||||||||
| 144 | __END__ | ||||||||||||||||||||||