Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating a program in a CompUnit::PrecompilationStore?

Tags:

raku

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.

like image 694
Richard Hainsworth Avatar asked Dec 12 '18 04:12

Richard Hainsworth


1 Answers

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 is intended to represent an immutable name, such that it will always point at the same content.

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.

like image 161
jjmerelo Avatar answered Oct 05 '22 09:10

jjmerelo