Permalink
Browse files

[lib/] replaced new methods with BUILD submethods

  • Loading branch information...
1 parent c61d818 commit 4dc85c610ac3f910378d8edde798ebda7ecdaf91 @masak committed Jun 8, 2009
Showing with 16 additions and 22 deletions.
  1. +6 −8 lib/Druid/Game.pm
  2. +5 −6 lib/Druid/Player.pm
  3. +5 −8 lib/Druid/View/Text.pm
View
@@ -35,17 +35,15 @@ has $.finished;
has $!latest-move;
-# RAKUDO: This could be done with BUILD instead, as soon as BUILD can
-# access private attributes. [perl #64388]
-method new(:$size = 3) {
+submethod BUILD(:$size = 3) {
die "Forbidden size: $size"
unless 3 <= $size <= 26;
- return self.bless( self.CREATE(),
- :size($size),
- :heights(map { [ 0 xx $size ] }, ^$size),
- :colors( map { [ 0 xx $size ] }, ^$size),
- :player-to-move(1) );
+ @!heights = map { [ 0 xx $size ] }, ^$size;
+ @!colors = map { [ 0 xx $size ] }, ^$size;
+ $!player-to-move = 1;
+ # RAKUDO: These attributes should be auto-initialized
+ $!size = $size;
}
=begin METHOD
View
@@ -16,12 +16,11 @@ has Druid::Game $!game handles <size layers colors heights make-move>;
=attr The color of this C<Druid::Player>'s pieces.
has Int $.color where { $_ == 1|2 };
-# RAKUDO: This could be done with BUILD instead, as soon as BUILD can
-# access private attributes. [perl #64388]
-method new(Druid::Game :$game!, Int :$color! where { $_ == 1|2 }) {
- my $player = self.bless( self.CREATE(), :game($game), :color($color) );
- $game.attach($player);
- return $player;
+submethod BUILD(Druid::Game :$game!, Int :$color! where { $_ == 1|2 }) {
+ $game.attach(self);
+ # RAKUDO: These attributes should be auto-initialized
+ $!game = $game;
+ $!color = $color;
}
method choose-move() { ... }
View
@@ -71,14 +71,11 @@ sub make-empty-board($size) {
};
}
-# RAKUDO: This could be done with BUILD instead, as soon as BUILD can
-# access private attributes. [perl #64388]
-method new(Druid::Game :$game!) {
- my $view = self.bless( self.CREATE(),
- :$game,
- :cached-board(make-empty-board($game.size)) );
- $game.attach($view);
- return $view;
+submethod BUILD(Druid::Game :$game!) {
+ $!cached-board = make-empty-board($game.size);
+ $game.attach(self);
+ # RAKUDO: These attributes should be auto-initialized
+ $!game = $game;
}
=begin METHOD

0 comments on commit 4dc85c6

Please sign in to comment.