annotate lib/IMPL/Config/Descriptor.pm @ 417:3ed0c58e9da3 ref20150831

working on di container, tests
author cin
date Mon, 02 Nov 2015 01:56:53 +0300
parents 3d24b10dd0d5
children df591e3afd10
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::Config::Descriptor;
413
af8d359ee4cc working on di container
cin
parents: 407
diff changeset
2 use strict;
af8d359ee4cc working on di container
cin
parents: 407
diff changeset
3 use IMPL::Exception();
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
4 use Scalar::Util qw(looks_like_number);
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
5
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
6 sub ACTIVATE_SINGLETON() { 1 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
7 sub ACTIVATE_CONTAINER() { 2 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
8 sub ACTIVATE_CONTEXT() { 3 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
9 sub ACTIVATE_CALL() { 4 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
10
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
11 my %activateNames = (
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
12 singleton => ACTIVATE_SINGLETON,
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
13 container => ACTIVATE_CONTAINER,
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
14 context => ACTIVATE_CONTEXT,
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
15 call => ACTIVATE_CALL
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
16 );
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
17
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
18 my %activateNamesLookup = map { $activateNames{$_}, $_ } keys %activateNames;
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19
413
af8d359ee4cc working on di container
cin
parents: 407
diff changeset
20 sub Activate {
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
21 my ( $this, $context ) = @_;
413
af8d359ee4cc working on di container
cin
parents: 407
diff changeset
22 die IMPL::NotImplementedException->new();
af8d359ee4cc working on di container
cin
parents: 407
diff changeset
23 }
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
25 sub ParseActivation {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
26 my $val = pop @_;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
27
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
28 return ACTIVATE_CALL unless $val;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
29
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
30 return grep $_ == $val,
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
31 ACTIVATE_SINGLETON,
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
32 ACTIVATE_CONTAINER,
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
33 ACTIVATE_CONTEXT, ACTIVATE_CALL ? $val : ACTIVATE_CALL
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
34 if looks_like_number($val);
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
35
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
36 return $activateNames{ lc($val) } || ACTIVATE_CALL;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
37 }
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
38
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
39 sub ActivationToString {
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
40 my $val = pop @_;
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
41
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
42 return ( $val && $activateNamesLookup{$val} ) || '';
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
43 }
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51 =head1 NAME
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 C<IMPL::Config::Descriptor> - the abstract base types for the service descriptors
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 =head1 SYNOPSIS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 =begin code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59 package MyDescriptor;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61 use IMPL::declare {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62 base => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 'IMPL::Config::Descriptor' => '@_'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67 sub Activate {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68 my ($this,$context) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70 my $service = $context->GetService('service');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71 my
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75 =end code
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77 =head1 MEMBERS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
78
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
79 =head1 SEE ALSO
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
80
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
81 =over
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
82
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
83 =item * L<ReferenceDescriptor> - describes a reference to the service
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
84
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
85 =item * L<ServiceDescriptor> - descibes a service factory
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
86
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
87 =item * L<ValueDescriptor> - describes a value
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
88
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
89 =back
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
90
415
3d24b10dd0d5 working on IMPL::Config::Container
cin
parents: 413
diff changeset
91 =cut