Skip to content

Instantly share code, notes, and snippets.

@gdey
Created October 23, 2012 03:26
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 gdey/3936461 to your computer and use it in GitHub Desktop.
Save gdey/3936461 to your computer and use it in GitHub Desktop.
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();
@gdey
Copy link
Author

gdey commented Oct 23, 2012

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

@gdey
Copy link
Author

gdey commented Oct 23, 2012

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