That's not apparently possible...
role Versioned {
method version () {
return self.^api;
}
}
class WithApi:ver<0.0.1>:auth<github:JJ>:api<0> does Versioned {}
class WithApi:ver<0.0.1>:auth<github:JJ>:api<1> does Versioned {}
say WithApi:api<0>.new.version;
say WithApi:api<1>.new.version;
This dies with
==SORRY!=== Error while compiling /home/jmerelo/progs/perl6/my-perl6-examples/api-versioned.p6
Redeclaration of symbol 'WithApi'
at /home/jmerelo/progs/perl6/my-perl6-examples/api-versioned.p6:11
------> 1>:auth<github:JJ>:api<1> does Versioned⏏ {}
So is it even possible to use
classes with different api
s, same name in a single program?
Update: if they are included in different files, this is the error obtained:
P6M Merging GLOBAL symbols failed: duplicate definition of symbol WrongType
Two things are creating a problem in this example:
class
is by default our
, which causes a name clashIf we adapt the code slightly:
role Versioned {
method version () {
return self.^api;
}
}
my constant one = my class WithApi:ver<0.0.1>:auth<github:JJ>:api<1> does Versioned {}
my constant two = my class WithApi:ver<0.0.1>:auth<github:JJ>:api<2> does Versioned {}
say one.version; # 1
say two.version; # 2
I did find that there is a bug for :api<0>
. Apparently this is considered to be equivalent to no :api
setting, resulting in an empty string rather than 0
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With