# New Ticket Created by Jonathan Stowe
# Please include the string: [perl #127860]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=127860 >
It appears that the Metamodel::WrapDispatcher can't find the candidate to
execute when the wrapped method is pre-compiled.
This can be recreated in several ways, first by wrapping the method in an
over-ridden add_method:
lib/Vum.pm:
class MetamodelX::FooHOW is Metamodel::ClassHOW {
method add_method(Mu \type, $name, &code) {
say "adding $name";
my &wrapper = method (|c) { say "running $name"; callsame; };
&code.wrap( &wrapper );
self.Metamodel::ClassHOW::add_method(type, $name, &code);
}
method compose(Mu \type) {
self.Metamodel::ClassHOW::compose(type);
}
}
my package EXPORTHOW {
package SUPERSEDE {
constant class = MetamodelX::FooHOW;
}
}
And lib/Boo.pm :
use Vum;
#no precompilation;
class Boo {
has $.rabble;
method rack() {
say "rabble : ";
}
}
And exercised with "perl6 -Ilib ...":
use Boo;
my $b = Boo.new(rabble => "hoodoo");
say $b.rack;
This will fail with:
Cannot invoke this object
in method <anon> at /home/jonathan/devel/perl6/Vum/lib/Vum.pm (Vum) line 4
in any enter at gen/moar/m-Metamodel.nqp line 3947
in block <unit> at tt line 5
(Which points to the enter method of WrapDispatch.) Which would appear that it
is not getting the appropriate Callable from .candidates[0]. With the "no
precompilation" un-commented in Boo.pm this will work fine.
Just to check that this wasn't something mysterious in the MOP it can also be
replicated with:
lib/Wom.pm:
module Wom {
multi sub trait_mod:<is>(Method $m, :$brapped!) is export {
$m.wrap(method (|c) { say "wrapped"; callsame });
}
}
lib/Bok.pm:
use Wom;
#no precompilation;
class Bok {
has $.rabble;
method rack() is brapped {
say "rabble : ";
}
}
And exercised with the similar script run with "perl6 -Ilib ..." :
use Bok;
my $b = Bok.new(rabble => "hoodoo");
say $b.rack;
Then this will also fail identically without the "no precompilation".
This afflicts OO::Monitors in the ecosystem which cannot be used in a module
that will be precompiled, and I suspect this is also at the heart of a problem
with Staticish which similarly doesn't work if used in a module which is
precompiled.
This is with:
This is Rakudo version 2016.03-98-g61d231c built on MoarVM version
2016.03-84-g4afd7b6