Skip to content

Instantly share code, notes, and snippets.

@FCO
Created December 13, 2016 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FCO/65196d4bff0362ef669ec61bafa50ae8 to your computer and use it in GitHub Desktop.
Save FCO/65196d4bff0362ef669ec61bafa50ae8 to your computer and use it in GitHub Desktop.
when I get a instance of a singleton inside of a trait_mod code, I get a object and when I get it on a regular code I get a different object... is that expected?
MacBook-Pro-de-Fernando:artigo fernando$ cat Fuzz.pm6
class Test::Fuzz {...}
my $instance = Test::Fuzz.bless;
class Test::Fuzz {
method new {!!!}
method instance(::?CLASS:U:) {
$instance
}
}
multi trait_mod:<is> (Routine $func, :$fuzzed!) is export {
say Test::Fuzz.instance.WHERE
}
MacBook-Pro-de-Fernando:artigo fernando$ cat Sum.pm6
unit module Sum;
use Fuzz;
sub sum($a, $b) is export is fuzzed {
$a + $b
}
MacBook-Pro-de-Fernando:artigo fernando$ perl6 -I. -MFuzz -MSum -e 'say Test::Fuzz.instance.WHERE'
4554770032
4508165144
MacBook-Pro-de-Fernando:artigo fernando$
but when I do that in the same "file" it gets the same object:
MacBook-Pro-de-Fernando:artigo fernando$ perl6 -I. -MFuzz -e 'sub test is fuzzed {}; say Test::Fuzz.instance.WHERE'
4456225336
4456225336
MacBook-Pro-de-Fernando:artigo fernando$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment