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?
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];
The output is always:
Some text
Some text
Update: My original question had '$handle' not '$new-handle' where '$new-resurrected' is defined. There is no change to the output.
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,
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.
As mentioned previously
load
methods cache, not the method call toprecomp
. You are expecting the parameter:force
to methodprecompile
to affect a later call to methodload
-- this is incorrect. We can easily prove that:force
is working as expected for precompiling by skipping the first call toload
and seeing if the final call toload
shows the updated results:which gives:
Some more text added