| 1 | package Spoon::IndexList; | ||
| 2 | 1 | ▶ | use Spiffy -selfless; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | ▶ | use IO::All; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 0 | ▶ | use DB_File; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 5 | |||
| 6 | sub index_list { | ||
| 7 | my $list = io(shift); | ||
| 8 | my $index = io($list . '.db')->dbm('DB_File')->rdonly; | ||
| 9 | unless ($index->exists) { | ||
| 10 | $index->assert->open; | ||
| 11 | $index->close; | ||
| 12 | } | ||
| 13 | unless ($list->exists) { | ||
| 14 | my $mtime = $index->mtime; | ||
| 15 | $list->print(''); | ||
| 16 | for (sort keys %$index) { | ||
| 17 | $list->print("$_\n"); | ||
| 18 | } | ||
| 19 | $index->close; | ||
| 20 | $list->close; | ||
| 21 | $list->utime($mtime - 1); | ||
| 22 | } | ||
| 23 | if ($list->mtime > $index->mtime) { | ||
| 24 | my %copy = %$index; | ||
| 25 | $index->close; | ||
| 26 | $index->rdonly(0)->rdwr(1)->open; | ||
| 27 | for my $key ($list->chomp->slurp) { | ||
| 28 | $key =~ s/^\s*(.*?)\s*$/$1/; | ||
| 29 | next unless $key; | ||
| 30 | $index->{$key} = 1; | ||
| 31 | delete $copy{$key}; | ||
| 32 | } | ||
| 33 | for my $key (keys %copy) { | ||
| 34 | delete $index->{$key}; | ||
| 35 | } | ||
| 36 | $index->rdonly(1)->rdwr(0)->close; | ||
| 37 | } | ||
| 38 | return $index; | ||
| 39 | } | ||