jjmerelo
jjmerelo

Reputation: 23537

Are private attributes hidden by default by .perl and .gist

That seems to be the case:

class Foo { has $!bar }; say Foo.new( :3bar ).perl # OUTPUT: «Foo.new␤» 

Documentation says it's implementation dependent, but I wonder if this actually makes sense.

Upvotes: 6

Views: 110

Answers (1)

Elizabeth Mattijsen
Elizabeth Mattijsen

Reputation: 26969

The .perl output is correct. Foo.new( :3bar ) does not do what you think. If you add a method bar() { $!bar }, you'll notice that the private attribute $!bar did not get set:

class Foo {
    has $!bar;
    method bar() { $!bar }
}
say Foo.new( :3bar ).bar;   # (Any)
say Foo.new( :3bar ).perl;  # Foo.new

The named parameter :3bar (aka bar => 3) is silently ignored, because there is no public attribute with the name bar.

If you want it to complain about this situation, then maybe https://modules.raku.org/dist/StrictNamedArguments is something for you.

Upvotes: 9

Related Questions