line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::DIC::Injectable; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
19
|
|
111120
|
use MooseX::DIC::Types; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
207
|
|
4
|
5
|
|
|
5
|
|
35
|
use aliased 'MooseX::DIC::Configuration::ServiceMetadata'; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
47
|
|
5
|
5
|
|
|
5
|
|
1167
|
use MooseX::DIC::Configuration::ServiceMetadata::Dependency 'from_attribute'; |
|
5
|
|
|
|
|
16
|
|
|
5
|
|
|
|
|
53
|
|
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
4418
|
use MooseX::Role::Parameterized; |
|
5
|
|
|
|
|
406435
|
|
|
5
|
|
|
|
|
30
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
parameter scope => ( isa => 'ServiceScope', default => 'singleton' ); |
10
|
|
|
|
|
|
|
parameter environment => ( isa => 'Str', default => 'default' ); |
11
|
|
|
|
|
|
|
parameter implements => ( isa => 'Str', predicate => 'has_implements' ); |
12
|
|
|
|
|
|
|
parameter qualifiers => ( isa => 'ArrayRef[Str]', default => sub { [] } ); |
13
|
|
|
|
|
|
|
parameter builder => ( isa => 'ServiceBuilder', default => 'Moose' ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
role { |
16
|
|
|
|
|
|
|
my ( $p, %args ) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# If this injectable is a factory, it must provide the build_service |
19
|
|
|
|
|
|
|
# method so that the container can use it. |
20
|
|
|
|
|
|
|
# The build_service will receive: |
21
|
|
|
|
|
|
|
# - the service metadata object |
22
|
|
|
|
|
|
|
# - the container |
23
|
|
|
|
|
|
|
# - injection point metadata |
24
|
|
|
|
|
|
|
if ( $p->builder eq 'Factory' ) { |
25
|
|
|
|
|
|
|
requires 'build_service'; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Inject in the package metadata the mooseX metadata |
30
|
|
|
|
|
|
|
$args{consumer}->add_method( |
31
|
|
|
|
|
|
|
get_service_metadata => sub { |
32
|
|
|
|
|
|
|
# Prepare dependencies metadata |
33
|
|
|
|
|
|
|
my %dependencies = |
34
|
4
|
|
|
|
|
272
|
map { ($_->name => from_attribute($_)) } |
35
|
14
|
|
|
14
|
|
79
|
$args{consumer}->get_all_attributes; |
|
|
|
|
14
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
return ServiceMetadata->new( |
38
|
|
|
|
|
|
|
class_name => $args{consumer}->{package}, |
39
|
14
|
|
|
|
|
720
|
scope => $p->scope, |
40
|
|
|
|
|
|
|
environment => $p->environment, |
41
|
|
|
|
|
|
|
qualifiers => $p->qualifiers, |
42
|
|
|
|
|
|
|
implements => $p->implements, |
43
|
|
|
|
|
|
|
builder => $p->builder, |
44
|
|
|
|
|
|
|
dependencies => \%dependencies |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
1; |