我正在处理由Rakudo Perl编译的文档,这些文档可以更新。
我将文档存储在CompUnit::预编译库::文件中
如何将旧版本更改为新版本?
下面的程序生成相同的输出,就好像新版本没有存储在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‘。输出没有变化。
发布于 2018-12-12 14:42:31
我认为答案可能是in the answer to other, similar question of yours here,CompUnits通常是不可变的。如果对象改变了,目标也需要改变。正如@ugexe所说,
$key旨在表示一个不可变的名称,以便它始终指向相同的内容。
因此,您可能实际上正在寻找类似于预编译的行为,但您可能不希望使用实际的CompUnits来实现此目的。
发布于 2018-12-15 01:25:30
如前所述,previously load方法缓存,而不是对precomp的方法调用。您期望方法precompile的参数:force会影响以后对方法load的调用--这是不正确的。我们可以通过跳过对load的第一次调用并查看最后一次对load的调用是否显示更新的结果,轻松地证明:force在预编译中如预期的那样工作:
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);
'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 more text added
https://stackoverflow.com/questions/53736139
复制相似问题