… | |
… | |
113 | sub read_pak($;$) { |
113 | sub read_pak($;$) { |
114 | my ($path, $cache) = @_; |
114 | my ($path, $cache) = @_; |
115 | |
115 | |
116 | eval { |
116 | eval { |
117 | defined $cache |
117 | defined $cache |
|
|
118 | && -e $cache |
118 | && -M $cache < -M $path |
119 | && -M $cache < -M $path |
119 | && Storable::retrieve $cache |
120 | && Storable::retrieve ($cache) |
120 | } or do { |
121 | } or do { |
121 | my %pak; |
122 | my %pak; |
122 | |
123 | |
123 | open my $fh, "<:raw", $path |
124 | open my $fh, "<:raw", $path |
124 | or Carp::croak "$_[0]: $!"; |
125 | or Carp::croak "$_[0]: $!"; |
… | |
… | |
126 | my ($type, $id, $len, $path) = split; |
127 | my ($type, $id, $len, $path) = split; |
127 | $path =~ s/.*\///; |
128 | $path =~ s/.*\///; |
128 | read $fh, $pak{$path}, $len; |
129 | read $fh, $pak{$path}, $len; |
129 | } |
130 | } |
130 | |
131 | |
131 | Storable::nstore \%pak, $cache |
132 | Storable::nstore (\%pak, $cache) |
132 | if defined $cache; |
133 | if defined $cache; |
133 | |
134 | |
134 | \%pak |
135 | \%pak |
135 | } |
136 | } |
136 | } |
137 | } |
… | |
… | |
138 | sub read_arch($;$) { |
139 | sub read_arch($;$) { |
139 | my ($path, $cache) = @_; |
140 | my ($path, $cache) = @_; |
140 | |
141 | |
141 | eval { |
142 | eval { |
142 | defined $cache |
143 | defined $cache |
|
|
144 | && -e $cache |
143 | && -M $cache < -M $path |
145 | && -M $cache < -M $path |
144 | && Storable::retrieve $cache |
146 | && Storable::retrieve ($cache) |
145 | } or do { |
147 | } or do { |
146 | my %arc; |
148 | my %arc; |
147 | my ($more, $prev); |
149 | my ($more, $prev); |
148 | |
150 | |
149 | open my $fh, "<:raw", $path |
151 | open my $fh, "<:raw", $path |
… | |
… | |
204 | } |
206 | } |
205 | } |
207 | } |
206 | |
208 | |
207 | undef $parse_block; # work around bug in perl not freeing $fh etc. |
209 | undef $parse_block; # work around bug in perl not freeing $fh etc. |
208 | |
210 | |
209 | Storable::nstore \%arc, $cache |
211 | Storable::nstore (\%arc, $cache) |
210 | if defined $cache; |
212 | if defined $cache; |
211 | |
213 | |
212 | \%arc |
214 | \%arc |
213 | } |
215 | } |
214 | } |
216 | } |
… | |
… | |
263 | |
265 | |
264 | } else { |
266 | } else { |
265 | # single face |
267 | # single face |
266 | return (0, 0, 0, 0); |
268 | return (0, 0, 0, 0); |
267 | } |
269 | } |
268 | } |
|
|
269 | |
|
|
270 | sub init($) { |
|
|
271 | my ($cachedir) = @_; |
|
|
272 | |
|
|
273 | return if %ARCH; |
|
|
274 | |
|
|
275 | mkdir 0777, $cachedir; |
|
|
276 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
|
|
277 | } |
270 | } |
278 | |
271 | |
279 | =item $type = arch_attr $arch |
272 | =item $type = arch_attr $arch |
280 | |
273 | |
281 | Returns a hashref describing the object and its attributes. It can contain |
274 | Returns a hashref describing the object and its attributes. It can contain |
… | |
… | |
379 | # return(edit_type); |
372 | # return(edit_type); |
380 | # |
373 | # |
381 | # |
374 | # |
382 | } |
375 | } |
383 | |
376 | |
|
|
377 | sub init($) { |
|
|
378 | my ($cachedir) = @_; |
|
|
379 | |
|
|
380 | return if %ARCH; |
|
|
381 | |
|
|
382 | mkdir $cachedir, 0777; |
|
|
383 | *ARCH = read_arch "$LIB/archetypes", "$cachedir/archetypes.pst"; |
|
|
384 | } |
|
|
385 | |
384 | $CACHEDIR ||= $ENV{HOME} ? "$ENV{HOME}/.crossfire" : File::Spec->tmpdir; |
386 | $CACHEDIR ||= $ENV{HOME} ? "$ENV{HOME}/crossfire" : File::Spec->tmpdir; |
385 | |
387 | |
386 | init $CACHEDIR; |
388 | init $CACHEDIR; |
387 | |
389 | |
388 | =head1 AUTHOR |
390 | =head1 AUTHOR |
389 | |
391 | |