Created
October 23, 2012 03:26
-
-
Save gdey/3936461 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; | |
class Task { | |
has &.callback; | |
has Task @.dependencies; | |
has Bool $.done; | |
method new( &callback, *@dependencies ){ | |
self.bless(*, :&callback, :@dependencies ); | |
} | |
method add-dependency( Task $dependency ){ | |
push @!dependencies, $dependency; | |
} | |
method perform(){ | |
unless $!done { | |
.perform() for @!dependencies; | |
&!callback(); | |
$!done = True; | |
} | |
} | |
}; | |
my $eat = Task.new( { say 'eating dinner1.'} ); | |
$eat.add-dependency( Task.new( { say 'making dinner' } ) ); | |
#my $eat = Task.new( { say 'eating dinner. NOM!' }, | |
# Task.new( { say 'making dinner' }, | |
# Task.new( { say 'buying food' }, | |
# Task.new( { say 'making some money' } ), | |
# Task.new( { say 'going to the store.' } ) | |
# ), | |
# Task.new( { say 'cleaning kitchen' } ) | |
# ) | |
#); | |
$eat.perform(); |
perl6 --version
This is perl6 version 2012.09.1 built on parrot 4.6.0 revision 0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Error I get is:
perl6 Task.pm
Nominal type check failed for parameter '@Dependencies'; expected Positional but got Array instead
in method new at Task.pm:8
in block at Task.pm:24