Skip to content

Instantly share code, notes, and snippets.

@lizmat
Last active September 20, 2022 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lizmat/e30c6866ba3a886dcfd5956ed62caf6f to your computer and use it in GitHub Desktop.
Save lizmat/e30c6866ba3a886dcfd5956ed62caf6f to your computer and use it in GitHub Desktop.
A way to use but without instantiation
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