raku - 更新 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'。输出没有变化。
解决方案
我认为答案可能在您在这里的其他类似问题的答案中。一般来说, CompUnits 旨在是immutable。如果对象改变,目标也需要改变。正如@ugexe 所说,
$key
旨在表示一个不可变的名称,以便它始终指向相同的内容。
因此,您实际上可能正在寻找类似 precomp 的行为,但您可能不想使用实际的 CompUnits 来执行此操作。
推荐阅读
- c# - 使单个方法适用于多个 WPF 元素
- javascript - React App 未在 azure app 服务中启动
- python - 如何使用python将所有输出保存在json文件中
- ios - 如何修复 window.open('http://maps.apple.com/?q=', '_system')?
- php - 编辑 Bootstrap 风格的个人资料卡
- sql - INSERT 存储过程的返回值
- python - 有什么方法可以更改函数外部定义的变量或函数
- sql-server - 将参数传递给 IN 运算符 SQL Server 的最佳方法是什么
- r - R 帮助转换日期时间
- python - Pandas:返回包含最少数量的区分大小写的单词的行,并且每个单词都跟随一个新行( '\n' )