Mercurial > pub > Impl
comparison _test/temp.pl @ 418:3f38dabaf5cc ref20150831
sync
author | cin |
---|---|
date | Mon, 28 Dec 2015 15:11:35 +0300 |
parents | 3ed0c58e9da3 |
children | bbc4739c4d48 |
comparison
equal
deleted
inserted
replaced
417:3ed0c58e9da3 | 418:3f38dabaf5cc |
---|---|
1 #!/usr/bin/perl | 1 #!/usr/bin/perl |
2 use strict; | 2 use strict; |
3 use Carp; | 3 use Carp; |
4 use Time::HiRes qw(gettimeofday tv_interval); | 4 use Time::HiRes qw(gettimeofday tv_interval); |
5 use Scalar::Util qw(blessed refaddr); | 5 use Scalar::Util qw(blessed refaddr); |
6 use YAML::XS qw(Dump); | 6 use YAML::XS qw(Dump Load); |
7 | 7 |
8 my $t = [gettimeofday]; | 8 |
9 | 9 |
10 use IMPL::require { | 10 use IMPL::require { |
11 Container => 'IMPL::Config::Container', | 11 Container => 'IMPL::Config::Container', |
12 Service => 'IMPL::Config::ServiceDescriptor', | 12 Service => 'IMPL::Config::ServiceDescriptor', |
13 Reference => 'IMPL::Config::ReferenceDescriptor', | 13 Reference => 'IMPL::Config::ReferenceDescriptor', |
14 Value => 'IMPL::Config::ValueDescriptor' | 14 Value => 'IMPL::Config::ValueDescriptor' |
15 }; | 15 }; |
16 | 16 |
17 my $c1 = Container->new(); | 17 my $data; |
18 { | |
19 open my $h, "sample.yaml" or die; | |
20 binmode $h; | |
21 local $/; | |
22 $data = <$h>; | |
23 } | |
18 | 24 |
19 $c1->Register('db', Service->new( | 25 my $t = [gettimeofday]; |
20 type => 'Foo::Data', | |
21 norequire => 1, | |
22 activation => 'container' | |
23 ) ); | |
24 | 26 |
25 $c1->Register(['sec', 'ldap'], Reference->new('db') ); | 27 print Dump Load($data); |
26 | |
27 $c1->Register('mixed', Value->new([ | |
28 Reference->new('db'), | |
29 Reference->new('sec'), | |
30 Reference->new('ldap') | |
31 ])); | |
32 | |
33 my $c2 = Container->new($c1); | |
34 | |
35 my $data = [ $c1->Resolve('mixed')] ; | |
36 | 28 |
37 print "Activated: ",tv_interval($t,[gettimeofday]),"\n"; | 29 print "Activated: ",tv_interval($t,[gettimeofday]),"\n"; |
38 | 30 |
39 print Dump($data); | |
40 | |
41 | |
42 package Foo::Data; | |
43 use IMPL::declare { | |
44 base => [ | |
45 'IMPL::Object' => undef | |
46 ] | |
47 }; | |
48 | 31 |
49 1; | 32 1; |