/
Dependency.pm
91 lines (65 loc) · 2.07 KB
/
Dependency.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package Bread::Board::Dependency;
# ABSTRACT: dependency for a service
use Moose;
use Bread::Board::Service;
with 'Bread::Board::Traversable';
has 'service_path' => (
is => 'ro',
isa => 'Str',
predicate => 'has_service_path'
);
has 'service_name' => (
is => 'ro',
isa => 'Str',
lazy => 1,
default => sub {
my $self = shift;
($self->has_service_path)
|| confess "Could not determine service name without service path";
(split '/' => $self->service_path)[-1];
}
);
has 'service_params' => (
is => 'ro',
isa => 'HashRef',
predicate => 'has_service_params'
);
has 'service' => (
is => 'ro',
does => 'Bread::Board::Service | Bread::Board::Dependency',
lazy => 1,
default => sub {
my $self = shift;
($self->has_service_path)
|| confess "Could not fetch service without service path";
$self->fetch($self->service_path);
},
handles => [ 'get', 'is_locked', 'lock', 'unlock' ]
);
__PACKAGE__->meta->make_immutable;
no Moose; 1;
__END__
=head1 DESCRIPTION
This class holds the information for a dependency of a
L<service|Bread::Board::Service::WithDependencies>. When L<resolving
dependencies|Bread::Board::Service::WithDependencies/resolve_dependencies>,
instances of this class will be used to access the services that will
provide the depended-on values.
This class consumes the L<Bread::Board::Traversable> role to retrieve
services given their path.
=attr C<service_path>
The path to use (possibly relative to the dependency itself) to access
the L</service>.
=method C<has_service_path>
Predicate for the L</service_path> attribute.
=attr C<service>
The service this dependency points at. Usually built lazily from the
L</service_path>, but could just be passed in to the constructor.
=attr C<service_name>
Name of the L</service>, defaults to the last element of the
L</service_path>.
=method C<get>
=method C<is_locked>
=method C<lock>
=method C<unlock>
These methods are delegated to the L</service>.