-
-
Save lizmat/e30c6866ba3a886dcfd5956ed62caf6f to your computer and use it in GitHub Desktop.
A way to use but without instantiation
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
role File::HomeDir::Win32 { | |
method my-home() { dd } | |
method my-desktop() { dd } | |
} | |
role File::HomeDir::MacOSX { | |
method my-home() { dd } | |
method my-desktop() { dd } | |
} | |
role File::HomeDir::Unix { | |
method my-home() { dd } | |
method my-desktop() { dd } | |
} | |
class File::HomeDir { | |
my $singleton; | |
sub singleton() { | |
without $singleton { | |
$_ = File::HomeDir but $*DISTRO.is-win | |
?? File::HomeDir::Win32 | |
!! $*DISTRO.name.starts-with('macos') | |
?? File::HomeDir::MacOSX | |
!! File::HomeDir::Unix; | |
} | |
$singleton | |
} | |
method my-home() { singleton.my-home } | |
method my-desktop() { singleton.my-desktop } | |
} | |
File::HomeDir.my-home; | |
File::HomeDir.my-desktop; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment