Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Make it actually work on nom #2

Merged
merged 1 commit into from

2 participants

@tadzik

No description provided.

@jasonmay jasonmay merged commit 573b324 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
6 lib/IoC.pm6
@@ -15,7 +15,7 @@ sub container($pair) is export {
$container-name = $pair.key;
- unless $pair.value.^isa('Block') {
+ unless $pair.value ~~ Callable {
die "Second param must be invocable";
}
@@ -28,7 +28,7 @@ sub contains(Block $sub) is export { return $sub }
sub service($pair) is export {
my %params = ('name' => $pair.key);
- if $pair.value.^isa('Str') {
+ if $pair.value ~~ Str {
%params<value> = $pair.value;
}
else {
@@ -133,7 +133,7 @@ to http://github.com/jasonmay/perl6-ioc/
=item L<IoC::Container> - Container of all your application components
-=item L<IoC::Service> - Serice representing a component in your application
+=item L<IoC::Service> - Service representing a component in your application
=back
View
4 lib/IoC/BlockInjection.pm6
@@ -4,9 +4,9 @@ class IoC::BlockInjection does IoC::Service {
has $.class;
method get {
- if ($.lifecycle eq 'Singleton') {
+ if $.lifecycle eq 'Singleton' {
return (
- $.instance ||= $!block.();
+ $.instance || self.initialize($!block.())
);
}
View
8 lib/IoC/ConstructorInjection.pm6
@@ -1,14 +1,14 @@
use IoC::Service;
class IoC::ConstructorInjection does IoC::Service {
has Str $.class;
- has %.dependencies = ();
+ has %.dependencies;
has %.parameters;
has $.container is rw;
method get {
- if ($.lifecycle eq 'Singleton') {
+ if $.lifecycle eq 'Singleton' {
return (
- $.instance ||= self.build-instance();
+ $.instance || self.initialize(self.build-instance());
);
}
@@ -22,7 +22,7 @@ class IoC::ConstructorInjection does IoC::Service {
%params{$pair.key} = $!container.fetch($pair.value).get();
};
- return eval("{$!class}.new(|%params)");
+ return ::($!class).new(|%params);
}
};
View
4 lib/IoC/Container.pm6
@@ -1,5 +1,5 @@
class IoC::Container {
- has %!services = ();
+ has %!services;
method add-service($name, $service) {
if $service.^can('container') {
@@ -22,7 +22,7 @@ class IoC::Container {
=head1 NAME
-IoC::Cnotainer
+IoC::Container
=head1 SYNOPSIS
View
7 lib/IoC/Service.pm6
@@ -4,6 +4,13 @@ role IoC::Service {
# for singletons
has Any $.instance;
+
+ method initialize($new) {
+ if $.instance {
+ die "Instance of $.name already initialized"
+ }
+ $!instance = $new;
+ }
};
=begin pod
Something went wrong with that request. Please try again.