更新 CompUnit::PrecompilationStore 中的程序? [英] Updating a program in a CompUnit::PrecompilationStore?

查看:34
本文介绍了更新 CompUnit::PrecompilationStore 中的程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working with documents compiled by Rakudo Perl and the documents can get updated.
I store the documents in a CompUnit::PrecompilationStore::File

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

How do I change an older version for a newer one?

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

The following program produces the same output, as if the newer version is not stored in CompUnit. What am I doing wrong?

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'.输出没有变化.

Update: My original question had '$handle' not '$new-handle' where '$new-resurrected' is defined. There is no change to the output.

推荐答案

我认为答案可能是 在此处回答您的其他类似问题 通常,CompUnit 旨在不可变.如果对象改变,目标也需要改变.正如@ugexe 所说,

I think the answer might be in the answer to other, similar question of yours here In general, CompUnits are intended to be immutable. If the object changes, the target needs to change too. As @ugexe says there,

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

$key is intended to represent an immutable name, such that it will always point at the same content.

因此,您实际上可能正在寻找类似 precomp 的行为,但您可能不想使用实际的 CompUnit 来做到这一点.

So you might be actually be looking for a precomp-like behavior, but you might not want to use the actual CompUnits to do that.

这篇关于更新 CompUnit::PrecompilationStore 中的程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆