Created
December 8, 2015 16:34
-
-
Save anonymous/80e3ad83226dd936865e 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
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