… | |
… | |
12 | |
12 | |
13 | use base 'Exporter'; |
13 | use base 'Exporter'; |
14 | |
14 | |
15 | use Carp (); |
15 | use Carp (); |
16 | use Storable; |
16 | use Storable; |
|
|
17 | use File::Spec; |
17 | use List::Util qw(min max); |
18 | use List::Util qw(min max); |
18 | |
19 | |
19 | #XXX: The map_* procedures scream for a map-object |
20 | #XXX: The map_* procedures scream for a map-object |
20 | |
21 | |
21 | our @EXPORT = |
22 | our @EXPORT = |
… | |
… | |
113 | my ($path, $cache) = @_; |
114 | my ($path, $cache) = @_; |
114 | |
115 | |
115 | eval { |
116 | eval { |
116 | defined $cache |
117 | defined $cache |
117 | && -M $cache < -M $path |
118 | && -M $cache < -M $path |
118 | && Storable::retrieve $cache |
119 | && Storable::retrieve ($cache) |
119 | } or do { |
120 | } or do { |
120 | my %pak; |
121 | my %pak; |
121 | |
122 | |
122 | open my $fh, "<:raw", $path |
123 | open my $fh, "<:raw", $path |
123 | or Carp::croak "$_[0]: $!"; |
124 | or Carp::croak "$_[0]: $!"; |
… | |
… | |
125 | my ($type, $id, $len, $path) = split; |
126 | my ($type, $id, $len, $path) = split; |
126 | $path =~ s/.*\///; |
127 | $path =~ s/.*\///; |
127 | read $fh, $pak{$path}, $len; |
128 | read $fh, $pak{$path}, $len; |
128 | } |
129 | } |
129 | |
130 | |
130 | Storable::nstore \%pak, $cache |
131 | Storable::nstore (\%pak, $cache) |
131 | if defined $cache; |
132 | if defined $cache; |
132 | |
133 | |
133 | \%pak |
134 | \%pak |
134 | } |
135 | } |
135 | } |
136 | } |
… | |
… | |
138 | my ($path, $cache) = @_; |
139 | my ($path, $cache) = @_; |
139 | |
140 | |
140 | eval { |
141 | eval { |
141 | defined $cache |
142 | defined $cache |
142 | && -M $cache < -M $path |
143 | && -M $cache < -M $path |
143 | && Storable::retrieve $cache |
144 | && Storable::retrieve ($cache) |
144 | } or do { |
145 | } or do { |
145 | my %arc; |
146 | my %arc; |
146 | my ($more, $prev); |
147 | my ($more, $prev); |
147 | |
148 | |
148 | open my $fh, "<:raw", $path |
149 | open my $fh, "<:raw", $path |
… | |
… | |
203 | } |
204 | } |
204 | } |
205 | } |
205 | |
206 | |
206 | undef $parse_block; # work around bug in perl not freeing $fh etc. |
207 | undef $parse_block; # work around bug in perl not freeing $fh etc. |
207 | |
208 | |
208 | Storable::nstore \%arc, $cache |
209 | Storable::nstore (\%arc, $cache) |
209 | if defined $cache; |
210 | if defined $cache; |
210 | |
211 | |
211 | \%arc |
212 | \%arc |
212 | } |
213 | } |
213 | } |
214 | } |
… | |
… | |
269 | sub init($) { |
270 | sub init($) { |
270 | my ($cachedir) = @_; |
271 | my ($cachedir) = @_; |
271 | |
272 | |
272 | return if %ARCH; |
273 | return if %ARCH; |
273 | |
274 | |
|
|
275 | mkdir $cachedir, 0777; |
274 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
276 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
275 | } |
277 | } |
276 | |
278 | |
277 | =item $type = arch_attr $arch |
279 | =item $type = arch_attr $arch |
278 | |
280 | |
… | |
… | |
377 | # return(edit_type); |
379 | # return(edit_type); |
378 | # |
380 | # |
379 | # |
381 | # |
380 | } |
382 | } |
381 | |
383 | |
382 | $CACHEDIR ||= "$ENV{HOME}/.crossfire"; |
384 | $CACHEDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir; |
383 | |
385 | |
384 | init $CACHEDIR; |
386 | init $CACHEDIR; |
385 | |
387 | |
386 | =head1 AUTHOR |
388 | =head1 AUTHOR |
387 | |
389 | |