diff options
author | Jesse Luehrs <doy@tozt.net> | 2012-12-27 15:22:04 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2012-12-27 15:22:04 -0600 |
commit | 0f5fa98ba50e53c6df312c19106b772b858f88de (patch) | |
tree | 9b6603457113baa4522a9102cb36a0a9e7262dbb /lib/Bread/Board.pm | |
parent | e6019e8a4187426482e18ebf80cc0ba482614486 (diff) | |
download | p6-bread-board-0f5fa98ba50e53c6df312c19106b772b858f88de.tar.gz p6-bread-board-0f5fa98ba50e53c6df312c19106b772b858f88de.zip |
a bit of restructuring and comment cleanup
Diffstat (limited to 'lib/Bread/Board.pm')
-rw-r--r-- | lib/Bread/Board.pm | 62 |
1 files 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.<dependencies> { - my $deps = {}; - for %params.<dependencies>.keys -> $name { - my $dep = %params.<dependencies>.{$name}; - $deps.{$name} = $dep.isa(Bread::Board::Dependency) - ?? $dep - !! Bread::Board::Dependency.new(service => $dep); - } - %params.<dependencies> = $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.<dependencies> { + my $deps = {}; + for %params.<dependencies>.keys -> $name { + my $dep = %params.<dependencies>.{$name}; + $deps.{$name} = $dep.isa(Bread::Board::Dependency) + ?? $dep + !! Bread::Board::Dependency.new(service => $dep); + } + %params.<dependencies> = $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.<dependencies> { + my $deps = {}; + for %params.<dependencies>.keys -> $name { + my $dep = %params.<dependencies>.{$name}; + $deps.{$name} = $dep.isa(Bread::Board::Dependency) + ?? $dep + !! Bread::Board::Dependency.new(service => $dep); + } + %params.<dependencies> = $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.<sub_containers>.isa(Array) { %params.<sub_containers> = %params.<sub_containers>.map(-> $c { $c.name => $c }).hash; |