Mercurial > pub > Impl
comparison lib/IMPL/Config/Container.pm @ 412:30e8c6a74937 ref20150831
working on di container (role based registrations)
author | cin |
---|---|
date | Mon, 21 Sep 2015 19:54:10 +0300 |
parents | c6e90e02dd17 |
children | af8d359ee4cc |
comparison
equal
deleted
inserted
replaced
411:ee36115f6a34 | 412:30e8c6a74937 |
---|---|
1 package IMPL::Config::Container; | 1 package IMPL::Config::Container; |
2 use strict; | |
3 | |
4 use IMPL::lang qw(:base); | |
5 use IMPL::declare { | |
6 require => { | |
7 Descriptor => 'IMPL::Config::Descriptor' | |
8 }, | |
9 base => [ | |
10 'IMPL::Object' => undef | |
11 ], | |
12 props => [ | |
13 roles => 'r', | |
14 services => 'r', | |
15 instances => 'r' | |
16 ] | |
17 }; | |
18 | |
19 my $nextRoleId = 1; | |
20 | |
21 use IMPL::Exception(); | |
22 | |
23 sub Register { | |
24 my ($this, $role, $service) = @_; | |
25 | |
26 die IMPL::InvalidArgumentException->new(role => 'The argument is required') unless $role; | |
27 die IMPL::InvalidArgumentException->new('service') unless is($service, Descriptor); | |
28 | |
29 if (isarray($role)) { | |
30 my $tempRole = "unnamed-" . $nextRoleId++; | |
31 $this->role->AddRole($tempRole, $role); | |
32 $role = $tempRole; | |
33 } | |
34 | |
35 $this->services->Register($role, $service); | |
36 | |
37 } | |
2 | 38 |
3 1; | 39 1; |
4 | 40 |
5 __END__ | 41 __END__ |
6 | 42 |