Created
February 18, 2015 11:45
-
-
Save Tux/ac2055cfd4b0806a538b to your computer and use it in GitHub Desktop.
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
use v6; | |
use Slang::Tuxic; | |
class C { | |
has Str $!foo = "A"; | |
has Str $!bar = "B"; | |
has Str $!baz = "C"; # Cannot be controlled from outside of class | |
method foo (Str $s) { $!foo = $s; } | |
method bar (Str $s) { $!bar = $s; } | |
submethod BUILD (*%init) { | |
for keys %init -> $attr { | |
my @can = self.can (lc $attr) or die "Unsupported attribute: $attr"; | |
.(self, %init{$attr}) for @can; | |
} | |
self!sanity_check; | |
} | |
method !sanity_check { | |
$!foo eq $!bar and die; | |
} | |
} | |
C.new (foo => "D"); | |
#C.new (box => "A"); # crash | |
C.new (bar => "A"); # crash | |
=> | |
use of uninitialized value $!bar of type Str in string context in method sanity_check at t.pl:22 | |
use of uninitialized value $!foo of type Str in string context in method sanity_check at t.pl:22 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment