Browse files

Make IoC::Container hold a type object rather than a string, rename $…

…!class to $!type
  • Loading branch information...
1 parent 573b324 commit e1d7d5c1e0702d3b98f0726f83db05fe09bc68d6 @tadzik tadzik committed Aug 25, 2011
Showing with 9 additions and 10 deletions.
  1. +3 −3 lib/IoC.pm6
  2. +1 −2 lib/IoC/BlockInjection.pm6
  3. +2 −2 lib/IoC/ConstructorInjection.pm6
  4. +2 −2 t/01-basic.t
  5. +1 −1 t/02-sugar.t
View
6 lib/IoC.pm6
@@ -36,13 +36,13 @@ sub service($pair) is export {
}
my $service;
- if %params<block> {
+ if %params.exists(<block>) {
$service = IoC::BlockInjection.new(|%params);
}
- elsif %params<class> {
+ elsif %params.exists(<type>) {
$service = IoC::ConstructorInjection.new(|%params);
}
- elsif %params<value> {
+ elsif %params.exists(<value>) {
$service = IoC::Literal.new(|%params);
}
else {
View
3 lib/IoC/BlockInjection.pm6
@@ -1,7 +1,6 @@
use IoC::Service;
class IoC::BlockInjection does IoC::Service {
- has Sub $.block;
- has $.class;
+ has Callable $.block;
method get {
if $.lifecycle eq 'Singleton' {
View
4 lib/IoC/ConstructorInjection.pm6
@@ -1,6 +1,6 @@
use IoC::Service;
class IoC::ConstructorInjection does IoC::Service {
- has Str $.class;
+ has $.type;
has %.dependencies;
has %.parameters;
has $.container is rw;
@@ -22,7 +22,7 @@ class IoC::ConstructorInjection does IoC::Service {
%params{$pair.key} = $!container.fetch($pair.value).get();
};
- return ::($!class).new(|%params);
+ return $!type.new(|%params);
}
};
View
4 t/01-basic.t
@@ -15,7 +15,7 @@ class Foo { has Bar $.bar; };
$c.add-service(
'foo', IoC::ConstructorInjection.new(
- :class('Foo'),
+ :type(Foo),
:lifecycle('Singleton'),
:dependencies({
'bar' => 'bar',
@@ -25,7 +25,7 @@ $c.add-service(
$c.add-service(
'bar', IoC::BlockInjection.new(
- :class('Bar'),
+ :type(Bar),
:lifecycle('Singleton'),
:block(sub {
return Bar.new;
View
2 t/02-sugar.t
@@ -9,7 +9,7 @@ class Foo { has Bar $.bar; };
my $c = container 'mycont' => contains {
service 'foo' => {
lifecycle => 'Singleton',
- 'class' => 'Foo',
+ type => Foo,
dependencies => {'bar' => 'bar'},
};

0 comments on commit e1d7d5c

Please sign in to comment.