| 1 | package File::Mork; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use vars qw($VERSION $ERROR); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | $VERSION = "0.4"; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | File::Mork - a module to read Mozilla URL history files | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | my $mork = File::Mork->new($filename, verbose => 1) | ||||||||||||||||||||||||||||||||||||||||||
| 17 | || die $File::Mork::ERROR."\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | foreach my $entry ($mork->entries) { | ||||||||||||||||||||||||||||||||||||||||||
| 21 | while (my($key,$val) = each %$entry) { | ||||||||||||||||||||||||||||||||||||||||||
| 22 | printf ("%14s = %s\n", $key, $val); | ||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | This is a module that can read the Mozilla URL history file -- normally | ||||||||||||||||||||||||||||||||||||||||||
| 29 | $HOME/.mozilla/default/*.slt/history.dat -- and extract the id, url, | ||||||||||||||||||||||||||||||||||||||||||
| 30 | name, hostname, first visted dat, last visited date and visit count. | ||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | To find your history file it might be worth using B<Mozilla::Backup> | ||||||||||||||||||||||||||||||||||||||||||
| 33 | which has some platform-independent code for finding the profiles of | ||||||||||||||||||||||||||||||||||||||||||
| 34 | various Mozilla-isms (including Firefox, Camino, K-Meleon, etc.). | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =head2 new <file> [opts] | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | Takes a filename and parses that file. | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | Returns C<undef> on error, setting C<$File::Mork::Error>. | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | Takes an optional hash of options | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | =item | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | verbose | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | A value up to 3 - defines the level of verbosity | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | =item | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | age | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | A ctime which forces C<File::Mork> to only parse entries later than this. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | my ($class, $file, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | my $self = bless \%opts, $class; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 2 | ▶ | $self->{verbose} ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"verbose"} ||= 0
MC/DC0%0/1
$self->{"verbose"} ||= 0
$self->{"verbose"}
Truth table50%1/2
A
A= $self->{"verbose"}
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | unless ($self->parse($file)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | $ERROR = $self->{error}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # Define the messy regexen up here | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | my $top_level_comment = qr@//.*\n@; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | my $key_table_re = qr/ < \s* < # "< <" | |||||||||||||||||||||||||||||||||||||||||
| 88 | \( a=c \) > # "(a=c)>" | ||||||||||||||||||||||||||||||||||||||||||
| 89 | (?> ([^>]*) ) > \s* # Grab anything that's not ">" | ||||||||||||||||||||||||||||||||||||||||||
| 90 | /sx; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | my $value_table_re = qr/ < ( .*?\) )> \s* /sx; | |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 3 | my $table_re = qr/ \{ -? # "{" or "{-" | |||||||||||||||||||||||||||||||||||||||||
| 95 | [\da-f]+ : # hex, ":" | ||||||||||||||||||||||||||||||||||||||||||
| 96 | (?> .*?\{ ) # Eat up to a {... | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ((?> .*?\} ) # and then the closing }... | ||||||||||||||||||||||||||||||||||||||||||
| 98 | (?> .*?\} )) # Finally, grab the table section | ||||||||||||||||||||||||||||||||||||||||||
| 99 | \s* /six; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | my $row_re = qr/ ( (?> \[ [^]]* \] # "["..."]" | |||||||||||||||||||||||||||||||||||||||||
| 102 | \s*)+ ) # Perhaps repeated many times | ||||||||||||||||||||||||||||||||||||||||||
| 103 | /sx; | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 3 | my $section_begin_re = qr/ \@\$\$\{ # "@$${" | |||||||||||||||||||||||||||||||||||||||||
| 106 | ([\dA-F]+) # hex | ||||||||||||||||||||||||||||||||||||||||||
| 107 | \{\@ \s* # "{@" | ||||||||||||||||||||||||||||||||||||||||||
| 108 | /six; | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 3 | my $crlf = qr/\x0a\x0d|\x0d\x0a|\x0a|\x0d/; # We are liberal in what we accept. | |||||||||||||||||||||||||||||||||||||||||
| 112 | # But then, so is a six dollar whore. | ||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | =head2 parse <file> | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | Internal method to parse the file. Obviously. | ||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | sub parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=18 SCAR=29.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 2 | my ($self, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 2 | ▶ | $self->{since} = ($self->{age} ? time() - $self->{age} : 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 2 | $self->{section} = "top level"; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | $self->{section_end_re} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # Read in the file. | ||||||||||||||||||||||||||||||||||||||||||
| 131 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 2 | local $/ = undef; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | local *IN; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 2 | $self->{file} = $file; | |||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | $self->{total} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | $self->{skipped} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | ▶ | unless (open (IN, $file)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | $self->{error} = "Couldn't open $file : $!"; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | $self->debug("reading ...",1); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | my $body = <IN>; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | close IN; | |||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $body =~ s/($crlf)/\n/gs; # Windows Mozilla uses \r\n | |||||||||||||||||||||||||||||||||||||||||
| 151 | # Presumably Mac Mozilla is similarly dumb | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | $body =~ s/\\\\/\$5C/gs; # Sometimes backslash is quoted with a | |||||||||||||||||||||||||||||||||||||||||
| 154 | # backslash; convert to hex. | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 1 | $body =~ s/\\\)/\$29/gs; # close-paren is quoted with a backslash; | |||||||||||||||||||||||||||||||||||||||||
| 156 | # convert to hex. | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 1 | $body =~ s/\\\n//gs; # backslash at end of line is continuation. | |||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||
| 159 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 160 | # Figure out what we're looking at, and parse it. | ||||||||||||||||||||||||||||||||||||||||||
| 161 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | $self->debug("parsing ...",1); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | pos($body) = 0; | |||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | my $length = length($body); | |||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 1 | ▶ | while( pos($body) < $length ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 10 | my $section_end_re = $self->{section_end_re}; | |||||||||||||||||||||||||||||||||||||||||
| 169 | # Key table | ||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 10 | ▶ | if ( $body =~ m/\G$key_table_re/gc ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | return unless $self->parse_key_table($1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | # Values | ||||||||||||||||||||||||||||||||||||||||||
| 175 | } elsif ( $body =~ m/\G$value_table_re/gco ) { | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 2 | ▶ | return unless $self->parse_value_table($1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # Table | ||||||||||||||||||||||||||||||||||||||||||
| 179 | } elsif ( $body =~ m/\G$table_re/gco ) { | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 2 | ▶ | return unless $self->parse_table($1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | # Rows (-> table) | ||||||||||||||||||||||||||||||||||||||||||
| 183 | } elsif ( $body =~ m/\G$row_re/gco ) { | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | return unless $self->parse_table($1); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # Section begin | ||||||||||||||||||||||||||||||||||||||||||
| 187 | } elsif ( $body =~ m/\G$section_begin_re/gco ) { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 2 | my $section = $1; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 2 | $self->{section_end_re} = qr/\@\$\$\}$section\}\@\s*/s; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 2 | $self->{section} = $section; | |||||||||||||||||||||||||||||||||||||||||
| 191 | # Section end | ||||||||||||||||||||||||||||||||||||||||||
| 192 | ▶ | } elsif ( $section_end_re && $body =~ m/\G$section_end_re/gc ) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$section_end_re and $body =~ /\G$section_end_re/cg
MC/DC50%1/2
$section_end_re and $body =~ /\G$section_end_re/cg
$section_end_re
$body =~ /\G$section_end_re/cg
Truth table66%2/3
A and B
A= $section_end_reB= $body =~ /\G$section_end_re/cg
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 2 | $self->{section_end_re} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 2 | $self->{section} = "top level"; | |||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | # Comment | ||||||||||||||||||||||||||||||||||||||||||
| 197 | } elsif ( $body =~ m/\G$top_level_comment/gco ) { | ||||||||||||||||||||||||||||||||||||||||||
| 198 | #no-op | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 201 | # $body =~ m/\G (.{0,300}) /gcsx; print "<$1>\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | return $self->error($self->{section}.": Cannot parse"); | |||||||||||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | ▶ | if($self->{section_end_re}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return $self->error("Unterminated section ".$self->{section}); | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | $self->debug("sorting...",1); | |||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 7 | my @entries = map { File::Mork::Entry->new(%$_) } | |||||||||||||||||||||||||||||||||||||||||
| 214 | sort { $b->{LastVisitDate} <=> | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | $a->{LastVisitDate} } values(%{$self->{row_hash}}); | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | $self->debug("done! (".$self->{total}." total, ".$self->{skipped}." skipped)",1); | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | for (qw(key_table val_table row_hash total skipped)) { | |||||||||||||||||||||||||||||||||||||||||
| 220 | 5 | $self->{$_} = undef; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | $self->{entries} = \@entries; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | =head2 entries | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | Return a list of C<File::Mork::Entry> objects sorted by B<LastVisitDate>. | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 1 | ▶ | sub entries { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
entries: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | return @{$_[0]->{entries}}; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 239 | # parse a row and column table | ||||||||||||||||||||||||||||||||||||||||||
| 240 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | ▶ | sub parse_table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_table: called CC=14 SCAR=28.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 2 | my($self, $table_part) = (@_); | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 2 | $self->debug("",3); | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | # Assumption: no relevant spaces in values in this section | ||||||||||||||||||||||||||||||||||||||||||
| 248 | 2 | $table_part =~ s/\s+//g; | |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # print $table_part; #exit(0); | ||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | # Grab each complete [...] block | ||||||||||||||||||||||||||||||||||||||||||
| 253 | 2 | ▶ | while( $table_part =~ m/\G [^[]* \[ # find a "[" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | ( [^]]+ ) \] # capture up to "]" | ||||||||||||||||||||||||||||||||||||||||||
| 255 | /gcx ) { | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 7 | $_ = $1; | |||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 7 | my ($id, @cells) = split (m/[()]+/s); | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 7 | ▶ | next unless scalar(@cells); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | # Trim junk | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 7 | $id =~ s/^-//; | |||||||||||||||||||||||||||||||||||||||||
| 264 | 7 | $id =~ s/:.*//; | |||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | my %hash = ($self->{row_hash}->{$id}) ? %{$self->{row_hash}->{$id}} : | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | ( 'ID' => $id, | ||||||||||||||||||||||||||||||||||||||||||
| 268 | 'LastVisitDate' => 0 ); | ||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 7 | foreach (@cells) { | |||||||||||||||||||||||||||||||||||||||||
| 271 | 35 | ▶ | next unless $_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 35 | my ($keyi, $which, $vali) = | |||||||||||||||||||||||||||||||||||||||||
| 274 | m/^\^ ([-\dA-F]+) | ||||||||||||||||||||||||||||||||||||||||||
| 275 | ([\^=]) | ||||||||||||||||||||||||||||||||||||||||||
| 276 | (.*) | ||||||||||||||||||||||||||||||||||||||||||
| 277 | $/xi; | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 35 | ▶ | return $self->error("unparsable cell: $_\n") unless defined ($vali); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | # If the key isn't in the key table, ignore it | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 35 | my $key = $self->{key_table}->{$keyi}; | |||||||||||||||||||||||||||||||||||||||||
| 284 | 35 | ▶ | next unless defined($key); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||
| 286 | my $val = ($which eq '=' | ||||||||||||||||||||||||||||||||||||||||||
| 287 | ? $vali | ||||||||||||||||||||||||||||||||||||||||||
| 288 | 35 | ▶ | : $self->{val_table}->{$vali}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 35 | ▶ | if ($key eq 'LastVisitDate' || $key eq 'FirstVisitDate') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$key eq "LastVisitDate" or $key eq "FirstVisitDate"
MC/DC100%2/2
$key eq "LastVisitDate" or $key eq "FirstVisitDate"
$key eq "LastVisitDate"
$key eq "FirstVisitDate"
Truth table100%3/3
A or B
A= $key eq "LastVisitDate"B= $key eq "FirstVisitDate"
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 12 | $val = int ($val / 1000000); # we don't need milliseconds, dude. | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | 35 | $hash{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 295 | #print "$id: $key -> $val\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 7 | ▶ | if ($self->{age} && ($hash{LastVisitDate} || $self->{since}) < $self->{since}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$self->{"age"} and ($hash{"LastVisitDate"} || $self->{"since"}) < $self->{"since"}
$hash{'LastVisitDate'} || $self->{'since'}
MC/DC0%0/3
$self->{"age"} and ($hash{"LastVisitDate"} || $self->{"since"}) < $self->{"since"}
$self->{"age"}
$hash{'LastVisitDate'}
$self->{'since'}
Truth table25%1/4
A and B || C
A= $self->{"age"}B= $hash{'LastVisitDate'}C= $self->{'since'}
| |||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | $self->debug("skipping old: $hash{LastVisitDate} $hash{URL}",3); | |||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | $self->{skipped}++; | |||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 7 | $self->{total}++; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 7 | $self->{row_hash}->{$id} = \%hash; | |||||||||||||||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 313 | # parse a values table | ||||||||||||||||||||||||||||||||||||||||||
| 314 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 2 | ▶ | sub parse_value_table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_value_table: called CC=9 SCAR=22.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 317 | 2 | my($self, $val_part) = (@_); | |||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | ▶ | return 1 unless $val_part; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | my @pairs = split (m/\(([^\)]+)\)/, $val_part); | |||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | $val_part = undef; | |||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | $self->debug("",3); | |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 2 | foreach (@pairs) { | |||||||||||||||||||||||||||||||||||||||||
| 327 | 58 | ▶ | next unless (m/[^\s]/s); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 29 | my ($key, $val) = m/([\dA-F]*)[\t\n ]*=[\t\n ]*(.*)/i; | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 29 | ▶ | if (! defined ($val)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $self->debug($self->{section}.": unparsable val: $_"); | |||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 333 | } | ||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||
| 335 | # recognize the byte order of UTF-16 encoding | ||||||||||||||||||||||||||||||||||||||||||
| 336 | 29 | ▶ | if (! defined ($self->{byte_order}) && $val =~ m/(?:BE|LE)$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $self->{"byte_order"} and $val =~ /(?:BE|LE)$/
MC/DC50%1/2
not defined $self->{"byte_order"} and $val =~ /(?:BE|LE)$/
not defined $self->{"byte_order"}
$val =~ /(?:BE|LE)$/
Truth table66%2/3
not(A) and B
A= not defined $self->{"byte_order"}B= $val =~ /(?:BE|LE)$/
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 1 | $self->{byte_order} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | # Assume that URLs and LastVisited are never hexilated; so | ||||||||||||||||||||||||||||||||||||||||||
| 341 | # don't bother unhexilating if we won't be using Name, etc. | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 29 | ▶ | if($val =~ m/\$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 6 | ▶ | if ( defined $self->{byte_order} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 6 | my $encoding = 'UTF-16' . $self->{byte_order}; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 6 | $val =~ s/\$([\dA-F]{2})/chr(hex($1))/ge; | |||||||||||||||||||||||||||||||||||||||||
| 346 | 6 | $val = encode_utf8(decode($encoding, $val)); | |||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||
| 348 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 349 | # Approximate wchar_t -> ASCII and remove NULs | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $val =~ s/\$00//g; # faster if we remove these first | |||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $val =~ s/\$([\dA-F]{2})/chr(hex($1))/ge; | |||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||
| 355 | 29 | $self->{val_table}->{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 356 | 29 | $self->debug($self->{section}.": val $key = \"$val\"", 3); | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 2 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 363 | # parse a key table | ||||||||||||||||||||||||||||||||||||||||||
| 364 | ########################################################################## | ||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||
| 366 | 1 | ▶ | sub parse_key_table { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_key_table: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 367 | 1 | my ($self, $key_table) = (@_); | |||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | $self->debug("",3); | |||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | 1 | $key_table =~ s@\s+//.*$@@gm; | |||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | my @pairs = split (m/\(([^\)]+)\)/s, $key_table); | |||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | $key_table = undef; | |||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | foreach (@pairs) { | |||||||||||||||||||||||||||||||||||||||||
| 377 | 26 | ▶ | next unless (m/[^\s]/s); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 13 | my ($key, $val) = m/([\dA-F]+)\s*=\s*(.*)/i; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 13 | ▶ | return $self->error ("unparsable key: $_") unless defined ($val); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | # savie the other fields that we aren't interested in. | ||||||||||||||||||||||||||||||||||||||||||
| 382 | 13 | $self->{key_table}->{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 13 | $self->debug($self->{section}.": key $key = \"$val\"",3); | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||
| 389 | =head2 error <message> | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | Internal method to set the internal error message | ||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | sub error { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
error: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my ($self, $message) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | $self->{error} = $self->{file}.": $message"; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | =head2 debug <message> <priority> | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | Internal method to print out a debug message if it's a higher priority | ||||||||||||||||||||||||||||||||||||||||||
| 404 | than the the current verbosity level. | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 51 | ▶ | sub debug { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
debug: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 409 | 51 | my ($self, $message, $level) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 51 | ▶ | $level ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$level ||= 0
MC/DC0%0/1
$level ||= 0
$level
Truth table50%1/2
A
A= $level
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | 51 | ▶ | return if $self->{verbose} < $level; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | print STDERR "".(($message eq "")? "\n" : $self->{file}.": $message\n" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | =head1 THE UGLY TRUTH LAID BARE | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | I<Extracted from mork.pl> | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | In Netscape Navigator 1.0 through 4.0, the history.db file was just a | ||||||||||||||||||||||||||||||||||||||||||
| 421 | Berkeley DBM file. You could trivially bind to it from Perl, and pull | ||||||||||||||||||||||||||||||||||||||||||
| 422 | out the URLs and last-access time. In Mozilla, this has been replaced | ||||||||||||||||||||||||||||||||||||||||||
| 423 | with a "Mork" database for which no tools exist. | ||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||
| 425 | Let me make it clear that McCusker is a complete barking lunatic. | ||||||||||||||||||||||||||||||||||||||||||
| 426 | This is just about the stupidest file format I've ever seen. | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | http://www.mozilla.org/mailnews/arch/mork/primer.txt | ||||||||||||||||||||||||||||||||||||||||||
| 429 | http://jwz.livejournal.com/312657.html | ||||||||||||||||||||||||||||||||||||||||||
| 430 | http://www.jwz.org/doc/mailsum.html | ||||||||||||||||||||||||||||||||||||||||||
| 431 | http://bugzilla.mozilla.org/show_bug.cgi?id=241438 | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | In brief, let's count its sins: | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | =item | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | Two different numerical namespaces that overlap. | ||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | =item | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | It can't decide what kind of character-quoting syntax to use: | ||||||||||||||||||||||||||||||||||||||||||
| 444 | Backslash? Hex encoding with dollar-sign? | ||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||
| 446 | =item | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | C++ line comments are allowed sometimes, but sometimes // is just a | ||||||||||||||||||||||||||||||||||||||||||
| 449 | pair of characters in a URL. | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | =item | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | It goes to all this serious compression effort (two different | ||||||||||||||||||||||||||||||||||||||||||
| 454 | string-interning hash tables) and then writes out Unicode strings | ||||||||||||||||||||||||||||||||||||||||||
| 455 | without using UTF-8: writes out the unpacked wchar_t characters! | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | =item | ||||||||||||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||||||||||||
| 459 | Worse, it hex-encodes each wchar_t with a 3-byte encoding, meaning the | ||||||||||||||||||||||||||||||||||||||||||
| 460 | file size will be 3x or 6x (depending on whether whchar_t is 2 bytes or | ||||||||||||||||||||||||||||||||||||||||||
| 461 | 4 bytes.) | ||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||
| 463 | =item | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | It masquerades as a "textual" file format when in fact it's just | ||||||||||||||||||||||||||||||||||||||||||
| 466 | another binary-blob file, except that it represents all its magic | ||||||||||||||||||||||||||||||||||||||||||
| 467 | numbers in ASCII. It's not human-readable, it's not hand-editable, so | ||||||||||||||||||||||||||||||||||||||||||
| 468 | the only benefit there is to the fact that it uses short lines and | ||||||||||||||||||||||||||||||||||||||||||
| 469 | doesn't use binary characters is that it makes the file bigger. Oh wait, | ||||||||||||||||||||||||||||||||||||||||||
| 470 | my mistake, that isn't actually a benefit at all. | ||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||
| 472 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | Pure comedy. | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||||||||||||
| 477 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||
| 479 | Module-ised by Simon Wistow <simon@thegestalt.org> | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | based on | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | http://www.jwz.org/hacks/mork.pl | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | Created: 3-Mar-2004 by Jamie Zawinski, Anonymous, and Jacob Post. | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||
| 490 | Copyright © 2004 Jamie Zawinski <jwz@jwz.org> | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | Permission to use, copy, modify, distribute, and sell this software and its | ||||||||||||||||||||||||||||||||||||||||||
| 495 | documentation for any purpose is hereby granted without fee, provided that | ||||||||||||||||||||||||||||||||||||||||||
| 496 | the above copyright notice appear in all copies and that both that | ||||||||||||||||||||||||||||||||||||||||||
| 497 | copyright notice and this permission notice appear in supporting | ||||||||||||||||||||||||||||||||||||||||||
| 498 | documentation. No representations are made about the suitability of this | ||||||||||||||||||||||||||||||||||||||||||
| 499 | software for any purpose. It is provided "as is" without express or | ||||||||||||||||||||||||||||||||||||||||||
| 500 | implied warranty. | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | Might be a bit memory heavy? Could do with an iterator interface. | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | Can't write Mork dbs. | ||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||||||||||||||
| 510 | http://www.livejournal.com/users/jwz/312657.html | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | http://www.erys.org/resume/netscape/mork/jwz.html | ||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||
| 514 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | package File::Mork::Entry; | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 519 | 3 | ▶ | use vars qw($AUTOLOAD); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | File::Mork::Entry - an single entry in a mork DB | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | All methods except C<new> take an optional argument to set them. | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | =head2 new <%opts> | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | blesses C<%opts> into the class File::Mork::Entry | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | 7 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | 7 | my ($class, %self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 537 | 7 | return bless \%self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||
| 541 | =head2 ID | ||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||
| 543 | The internal id of the entry | ||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||
| 545 | =head2 URL | ||||||||||||||||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||||||||||||||||
| 547 | The url visited | ||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | =head2 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||
| 551 | The name of the url visited | ||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | =head2 Hostname | ||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||
| 555 | The hostname of the url visited | ||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||
| 557 | =head2 FirstVisitDate | ||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | The first time this url was visited as a C<ctime> | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | =head2 LastVisitDate | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | The last time this url was visited as a C<ctime> | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | =head2 Hidden | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | Whether this URL is hidden from the history list or not | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | =head2 VisitCount | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | The number of times this url has been visited | ||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | =head2 ByteOrder | ||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | The byte order - this is associated with ID number 1. | ||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 14 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 582 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 583 | 14 | my $attr = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||
| 584 | 14 | $attr =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | 14 | ▶ | $self->{$attr} = $_[0] if @_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 14 | return $self->{$attr}; | |||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||