| 1 | package Mail::Mbox::MessageParser::Cache; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 51 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 51 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 51 | ▶ | use Mail::Mbox::MessageParser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 51 | ▶ | use Mail::Mbox::MessageParser::MetaInfo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 51 | ▶ | use vars qw( $VERSION $_DEBUG @ISA ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 51 | ▶ | use vars qw( $_CACHE ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 51 | @ISA = qw( Exporter Mail::Mbox::MessageParser ); | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 51 | $VERSION = sprintf "%d.%02d%02d", q/1.30.2/ =~ /(\d+)/g; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 51 | *_ENTRY_STILL_VALID = \&Mail::Mbox::MessageParser::MetaInfo::_ENTRY_STILL_VALID; | |||||||||||||||||||||||||||
| 17 | sub _ENTRY_STILL_VALID; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 51 | *_CACHE = \$Mail::Mbox::MessageParser::MetaInfo::_CACHE; | |||||||||||||||||||||||||||
| 20 | 51 | *_WRITE_CACHE = \&Mail::Mbox::MessageParser::MetaInfo::WRITE_CACHE; | |||||||||||||||||||||||||||
| 21 | 51 | *_INITIALIZE_ENTRY = \&Mail::Mbox::MessageParser::MetaInfo::_INITIALIZE_ENTRY; | |||||||||||||||||||||||||||
| 22 | sub _WRITE_CACHE; | ||||||||||||||||||||||||||||
| 23 | sub _INITIALIZE_ENTRY; | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 51 | *_DEBUG = \$Mail::Mbox::MessageParser::_DEBUG; | |||||||||||||||||||||||||||
| 26 | 51 | *_dprint = \&Mail::Mbox::MessageParser::_dprint; | |||||||||||||||||||||||||||
| 27 | sub _dprint; | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub new | ||||||||||||||||||||||||||||
| 32 | 257 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||||||||||
| 33 | 257 | my ($proto, $self) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 257 | ▶ | carp "Need file_name option" unless defined $self->{'file_name'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 257 | ▶ | carp "Need file_handle option" unless defined $self->{'file_handle'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | carp "Call SETUP_CACHE() before calling new()" | ||||||||||||||||||||||||||||
| 39 | 257 | ▶ | unless exists $Mail::Mbox::MessageParser::MetaInfo::_CACHE_OPTIONS{'file_name'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 257 | bless ($self, __PACKAGE__); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 257 | $self->_init(); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 257 | return $self; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | sub _init | ||||||||||||||||||||||||||||
| 51 | 257 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 257 | my $self = shift; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 257 | _WRITE_CACHE(); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 257 | $self->SUPER::_init(); | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 257 | _INITIALIZE_ENTRY($self->{'file_name'}); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | sub reset | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | $self->SUPER::reset(); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | # If we're in the middle of parsing this file, we need to reset the cache | ||||||||||||||||||||||||||||
| 70 | 0 | _INITIALIZE_ENTRY($self->{'file_name'}); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | sub _read_prologue | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_read_prologue: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | _dprint "Reading mailbox prologue using cache"; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | my $prologue_length = $_CACHE->{$self->{'file_name'}}{'emails'}[0]{'offset'}; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | my $total_amount_read = 0; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | $total_amount_read += read($self->{'file_handle'}, $self->{'prologue'}, | |||||||||||||||||||||||||||
| 86 | $prologue_length-$total_amount_read, $total_amount_read); | ||||||||||||||||||||||||||||
| 87 | } while ($total_amount_read != $prologue_length); | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub read_next_email | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
read_next_email: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 94 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | my $entry_became_invalidated = 0; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | unless (defined $self->{'file_name'} && _ENTRY_STILL_VALID($self->{'file_name'})) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $self->{"file_name"} and _ENTRY_STILL_VALID($self->{"file_name"})
MC/DC0%0/2
defined $self->{"file_name"} and _ENTRY_STILL_VALID($self->{"file_name"})
defined $self->{"file_name"}
_ENTRY_STILL_VALID($self->{"file_name"})
Truth table0%0/3
A and B
A= defined $self->{"file_name"}B= _ENTRY_STILL_VALID($self->{"file_name"})
| |||||||||||||||||||||||||||||
| 99 | { | ||||||||||||||||||||||||||||
| 100 | 0 | $entry_became_invalidated = 1; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # Patch up the data structures for the Perl implementation | ||||||||||||||||||||||||||||
| 103 | $self->{'CURRENT_LINE_NUMBER'} = | ||||||||||||||||||||||||||||
| 104 | 0 | $_CACHE->{$self->{'file_name'}}{'emails'}[$self->{'email_number'}]{'line_number'}; | |||||||||||||||||||||||||||
| 105 | $self->{'CURRENT_OFFSET'} = | ||||||||||||||||||||||||||||
| 106 | 0 | $_CACHE->{$self->{'file_name'}}{'emails'}[$self->{'email_number'}]{'offset'}; | |||||||||||||||||||||||||||
| 107 | $self->{'READ_CHUNK_SIZE'} = | ||||||||||||||||||||||||||||
| 108 | 0 | $Mail::Mbox::MessageParser::Config{'read_chunk_size'}; | |||||||||||||||||||||||||||
| 109 | 0 | $self->{'READ_BUFFER'} = ''; | |||||||||||||||||||||||||||
| 110 | 0 | $self->{'END_OF_EMAIL'} = 0; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | # Invalidate the remaining data | ||||||||||||||||||||||||||||
| 113 | 0 | $#{ $_CACHE->{$self->{'file_name'}}{'emails'} } = $self->{'email_number'}; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | bless ($self, 'Mail::Mbox::MessageParser::Perl'); | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | return $self->read_next_email(); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | return undef if $self->end_of_file(); ## no critic (ProhibitExplicitReturnUndef) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | $self->{'email_line_number'} = | ||||||||||||||||||||||||||||
| 123 | 0 | $_CACHE->{$self->{'file_name'}}{'emails'}[$self->{'email_number'}]{'line_number'}; | |||||||||||||||||||||||||||
| 124 | $self->{'email_offset'} = | ||||||||||||||||||||||||||||
| 125 | 0 | $_CACHE->{$self->{'file_name'}}{'emails'}[$self->{'email_number'}]{'offset'}; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | my $email = ''; | |||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | $self->{'email_length'} = | ||||||||||||||||||||||||||||
| 130 | 0 | $_CACHE->{$self->{'file_name'}}{'emails'}[$self->{'email_number'}]{'length'}; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | { | ||||||||||||||||||||||||||||
| 133 | 0 | my $total_amount_read = length($email); | |||||||||||||||||||||||||||
| 134 | do { | ||||||||||||||||||||||||||||
| 135 | $total_amount_read += read($self->{'file_handle'}, $email, | ||||||||||||||||||||||||||||
| 136 | 0 | $self->{'email_length'}-$total_amount_read, $total_amount_read); | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | } while ($total_amount_read != $self->{'email_length'}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | unless ($_CACHE->{$self->{'file_name'}}{'emails'}[$self->{'email_number'}]{'validated'}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | my $current_time = localtime; | |||||||||||||||||||||||||||
| 142 | 0 | my $email_last_modified_time = localtime((stat($self->{'file_name'}))[9]); | |||||||||||||||||||||||||||
| 143 | my $cache_last_modified_time = | ||||||||||||||||||||||||||||
| 144 | 0 | localtime((stat($Mail::Mbox::MessageParser::MetaInfo::_CACHE_OPTIONS{'file_name'}))[9]); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | die <<EOF; | |||||||||||||||||||||||||||
| 147 | Cache data not validated. This should not occur. Please send an email to | ||||||||||||||||||||||||||||
| 148 | david\@coppit.org with the following information. | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | Debugging info: | ||||||||||||||||||||||||||||
| 151 | - Current time: $current_time | ||||||||||||||||||||||||||||
| 152 | - Email file: $self->{'file_name'} | ||||||||||||||||||||||||||||
| 153 | - Email file last modified time: $email_last_modified_time | ||||||||||||||||||||||||||||
| 154 | - Cache file: $Mail::Mbox::MessageParser::MetaInfo::_CACHE_OPTIONS{'file_name'} | ||||||||||||||||||||||||||||
| 155 | - Cache file last modified time: $cache_last_modified_time | ||||||||||||||||||||||||||||
| 156 | - Email number: $self->{'email_number'} | ||||||||||||||||||||||||||||
| 157 | - Email line number: $self->{'email_line_number'} | ||||||||||||||||||||||||||||
| 158 | - Email offset: $self->{'email_offset'} | ||||||||||||||||||||||||||||
| 159 | - Email length: $self->{'email_length'} | ||||||||||||||||||||||||||||
| 160 | - Entry became invalidated?: $entry_became_invalidated | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | It would also be really helpful if you could send the cache and email file, | ||||||||||||||||||||||||||||
| 163 | but I realize that many would not be comfortable doing that. | ||||||||||||||||||||||||||||
| 164 | EOF | ||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | $self->{'email_number'}++; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | $self->SUPER::read_next_email(); | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 0 | return \$email; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | #------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | sub _print_debug_information | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
_print_debug_information: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | return unless $_DEBUG; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | 0 | $self->SUPER::_print_debug_information(); | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | _dprint "Valid cache entry exists: " . | ||||||||||||||||||||||||||||
| 185 | 0 | ▶ | ($#{ $_CACHE->{$self->{'file_name'}}{'emails'} } != -1 ? "Yes" : "No"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 51 | 1; | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | __END__ | ||||||||||||||||||||||||||||