在CompUnit :: PrecompilationStore中更新程序?

Ric*_*rth 6 perl6

我正在使用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];
Run Code Online (Sandbox Code Playgroud)

输出总是:

Some text
Some text
Run Code Online (Sandbox Code Playgroud)

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

jjm*_*elo 4

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

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

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

  • 您正在强制预编译,但似乎期望它也强制加载以破坏缓存。这是两件不同的事情。预编译后重新启动程序,以便加载发生在空缓存上,您将看到更新。 (3认同)
  • 我再次重新阅读了@ugexe 的答案。我没有考虑不变性的程度。似乎有一些方法可以从缓存中删除内容(称为“删除”和“从缓存中删除”的方法)。如果没有什么可以强迫的话,那么:强迫的目的是什么? (2认同)