Skip to content

Instantly share code, notes, and snippets.

@phamer
Created October 19, 2015 21:21
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 phamer/a265d76ce94f7ea91e28 to your computer and use it in GitHub Desktop.
Save phamer/a265d76ce94f7ea91e28 to your computer and use it in GitHub Desktop.
array as attribute
#!/usr/bin/env perl6
use v6;
class Point {
has $.x is rw is required;
has $.y is rw is required;
method Str { "($.x,$.y)" }
}
class Line {
has Point $.point-start is rw is required;
has Point $.point-end is rw is required;
method Str { "$.point-start -- $.point-end" }
}
class Room {
has Line @!walls;
method read( ) {
my $l = Line.new( point-start => Point.new( x => 3, y => 4 ), point-end => Point.new( x => 5, y => 6 ) );
# fails with
# Cannot look up attributes in a type object
# in method read at ./array-member.p6:34
# in sub MAIN at ./array-member.p6:38
# in block <unit> at ./array-member.p6:38
say ">> new line $l";
push @!walls, $l;
}
}
sub MAIN( )
{
my $room = Room.read();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment