首页 > 解决方案 > 更新 CompUnit::PrecompilationStore 中的程序?

问题描述

我正在处理由 Rakudo Perl 编译的文档,并且这些文档可以得到更新。
我将文档存储在 CompUnit::PrecompilationStore::File

如何将旧版本更改为新版本?

下面的程序产生相同的输出,就好像新版本没有存储在 CompUnit 中一样。我究竟做错了什么?

use v6.c;
use nqp;
'cache'.IO.unlink if 'cache'.IO ~~ e;
my $precomp-store = CompUnit::PrecompilationStore::File.new(prefix=>'cache'.IO);
my $precomp = CompUnit::PrecompilationRepository::Default.new(store=> $precomp-store );
my $key = nqp::sha1('test.pod6');

'test.pod6'.IO.spurt(q:to/--END--/);
    =begin pod
    =TITLE More and more

    Some text

    =end pod
    --END--
$precomp.precompile('test.pod6'.IO, $key, :force);
my $handle = $precomp.load( $key )[0];
my $resurrected = nqp::atkey($handle.unit,'$=pod')[0];
say $resurrected.contents[1].contents[0];


'test.pod6'.IO.spurt(q:to/--END--/);
    =begin pod
    =TITLE More and more

    Some more text added

    =end pod
    --END--
# $precomp-store.unlock;
# fails with:
# Attempt to unlock mutex by thread not holding it
#  in block <unit> at comp-test.p6 line 30

$precomp.precompile('test.pod6'.IO, $key, :force);
my $new-handle = $precomp.load($key)[0];
my $new-resurrected = nqp::atkey($new-handle.unit,'$=pod')[0];
say $new-resurrected.contents[1].contents[0];

输出总是:

Some text
Some text

更新:我原来的问题有 '$handle' 而不是 '$new-handle' 定义了 '$new-resurrected'。输出没有变化。

标签: raku

解决方案


我认为答案可能在您在这里的其他类似问题的答案中。一般来说, CompUnits 旨在是immutable。如果对象改变,目标也需要改变。正如@ugexe 所说,

$key旨在表示一个不可变的名称,以便它始终指向相同的内容。

因此,您实际上可能正在寻找类似 precomp 的行为,但您可能不想使用实际的 CompUnits 来执行此操作。


推荐阅读