From 0f5fa98ba50e53c6df312c19106b772b858f88de Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 27 Dec 2012 15:22:04 -0600 Subject: a bit of restructuring and comment cleanup --- lib/Bread/Board.pm | 62 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/lib/Bread/Board.pm b/lib/Bread/Board.pm index d1d6385..14dca83 100644 --- a/lib/Bread/Board.pm +++ b/lib/Bread/Board.pm @@ -7,28 +7,10 @@ role Bread::Board::Service { has Str $.name; has Bread::Board::Container $.parent is rw = Bread::Board::Container; - # XXX not sure how to make these optional - specifying the types here - # makes it fail when the parameters aren't passed - # shouldn't the " = {}" part be taking care of that? + # TODO: typed hashes NYI # has Hash of Bread::Board::Dependency $.dependencies = {}; has $.dependencies = {}; - # XXX overriding new here is an extremely suboptimal solution - # does perl 6 have anything like moose's coercions? - method new (*%params is copy) { - if %params. { - my $deps = {}; - for %params..keys -> $name { - my $dep = %params..{$name}; - $deps.{$name} = $dep.isa(Bread::Board::Dependency) - ?? $dep - !! Bread::Board::Dependency.new(service => $dep); - } - %params. = $deps; - } - nextwith(|%params); - } - method get {*}; method get_dependency ($name) { @@ -37,9 +19,7 @@ role Bread::Board::Service { } role Bread::Board::HasParameters { - # XXX not sure how to make these optional - specifying the types here - # makes it fail when the parameters aren't passed - # shouldn't the " = {}" part be taking care of that? + # TODO: typed hashes NYI # has Hash of Hash $.parameters = {}; has $.parameters = {}; @@ -59,7 +39,9 @@ role Bread::Board::HasParameters { } } - # XXX why is this return necessary? + # TODO: for loops are currently lazy, so won't get evaluated until + # something evaluates the return value if they are the last statement + # in a method. this may change in the future, because it's pretty weird return; } } @@ -75,6 +57,21 @@ class Bread::Board::ConstructorInjection has $.class; has Str $.constructor_name is rw = 'new'; + # TODO: type coercions NYI + method new (*%params is copy) { + if %params. { + my $deps = {}; + for %params..keys -> $name { + my $dep = %params..{$name}; + $deps.{$name} = $dep.isa(Bread::Board::Dependency) + ?? $dep + !! Bread::Board::Dependency.new(service => $dep); + } + %params. = $deps; + } + nextwith(|%params); + } + method get (*%params is copy) { # XXX remove more duplication? self.check_parameters(%params); @@ -102,6 +99,21 @@ class Bread::Board::BlockInjection has Callable $.block; has $.class = Any; + # TODO: type coercions NYI + method new (*%params is copy) { + if %params. { + my $deps = {}; + for %params..keys -> $name { + my $dep = %params..{$name}; + $deps.{$name} = $dep.isa(Bread::Board::Dependency) + ?? $dep + !! Bread::Board::Dependency.new(service => $dep); + } + %params. = $deps; + } + nextwith(|%params); + } + method get (*%params is copy) { # XXX remove more duplication? self.check_parameters(%params); @@ -128,13 +140,13 @@ class Bread::Board::Literal does Bread::Board::Service { class Bread::Board::Container { has Str $.name; has Bread::Board::Container $.parent is rw = Bread::Board::Container; - # XXX again, as above + # TODO: typed hashes NYI' # has Hash of Bread::Board::Container $.sub_containers = {}; # has Hash of Bread::Board::Service $.services = {}; has $.sub_containers = {}; has $.services = {}; - # XXX again, as above + # TODO: type coercions NYI method new (*%params is copy) { if %params..isa(Array) { %params. = %params..map(-> $c { $c.name => $c }).hash; -- cgit v1.2.3