Created
September 28, 2024 10:05
-
-
Save lizmat/c123c39edf1be1738b08185fae45cb3f to your computer and use it in GitHub Desktop.
wayland76's question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adds BUILD-ARGS and POST-TWEAK | |
role BetterNew { | |
method new(*@positional is copy, *%named is copy) { | |
say "BetterNew.new"; | |
dd @positional; | |
for self.can('BUILD-ARGS') -> &method { | |
my @rvs = method(self, @positional, %named); | |
@positional := @rvs[0]; | |
%named := @rvs[1]; | |
} | |
dd %named; | |
my $this = callwith(|@positional, |%named); | |
# This is the point where I expect the object construction to have completed... | |
say "bn1"; | |
for $this.can('POST-TWEAK').reverse -> &method { | |
method($this); | |
} | |
$this | |
} | |
} | |
class A does BetterNew { | |
has Str $.object-name is rw; | |
has Str $.object-slug is rw; | |
method POST-TWEAK() { | |
# ... so why does this not work? | |
$!object-slug = $!object-name; | |
# $!object-slug ~~ s:g/\s/_/; | |
} | |
} | |
class B is A { | |
submethod BUILD-ARGS(@positional, %named) { | |
say "B.BUILD-ARGS"; | |
%named<object-name> = 'app ape'; | |
return @positional, %named; | |
} | |
submethod POST-TWEAK() { | |
say "B.POST-TWEAK"; | |
say self.object-slug; | |
} | |
} | |
my $b = B.new(); | |
say $b.object-slug; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment