Skip to content

Instantly share code, notes, and snippets.

Created December 8, 2015 16:34
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 anonymous/80e3ad83226dd936865e to your computer and use it in GitHub Desktop.
Save anonymous/80e3ad83226dd936865e to your computer and use it in GitHub Desktop.
class Wordlist {
has $.file = '/usr/share/dict/words';
has $.downcase = False;
has $!source handles 'pull-one';
method BUILDALL(|c) {
callsame;
if not defined $!source {
warn "\$!source={$!source.perl}";
warn "args={|c.perl} named={|c.hash.perl}";
if %(|c.hash){'source'}:exists {
die "'source' key passed, but not initialized";
}
$!source = open($!file);
}
}
}
sub first(@list) { for @list -> $item { return $item; } }
my $wl = Wordlist.new(:source<apple pear orange>);
say "Word from first feed: ", first($wl);
$wl = Wordlist.new(:file<./words>);
say "Word from second feed: ", first($wl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment