1package Bread::Board::Dependency;
2our $AUTHORITY = 'cpan:STEVAN';
3# ABSTRACT: dependency for a service
4$Bread::Board::Dependency::VERSION = '0.37';
5use Moose;
6
7use Bread::Board::Service;
8
9with 'Bread::Board::Traversable';
10
11has 'service_path' => (
12    is        => 'ro',
13    isa       => 'Str',
14    predicate => 'has_service_path'
15);
16
17has 'service_name' => (
18    is      => 'ro',
19    isa     => 'Str',
20    lazy    => 1,
21    default => sub {
22        my $self = shift;
23        ($self->has_service_path)
24            || confess "Could not determine service name without service path";
25        (split '/' => $self->service_path)[-1];
26    }
27);
28
29has 'service_params' => (
30    is        => 'ro',
31    isa       => 'HashRef',
32    predicate => 'has_service_params'
33);
34
35has 'service' => (
36    is       => 'ro',
37    does     => 'Bread::Board::Service | Bread::Board::Dependency',
38    lazy     => 1,
39    default  => sub {
40        my $self = shift;
41        ($self->has_service_path)
42            || confess "Could not fetch service without service path";
43        $self->fetch($self->service_path);
44    },
45    handles  => [ 'get', 'is_locked', 'lock', 'unlock' ]
46);
47
48__PACKAGE__->meta->make_immutable;
49
50no Moose; 1;
51
52__END__
53
54=pod
55
56=encoding UTF-8
57
58=head1 NAME
59
60Bread::Board::Dependency - dependency for a service
61
62=head1 VERSION
63
64version 0.37
65
66=head1 DESCRIPTION
67
68This class holds the information for a dependency of a
69L<service|Bread::Board::Service::WithDependencies>. When L<resolving
70dependencies|Bread::Board::Service::WithDependencies/resolve_dependencies>,
71instances of this class will be used to access the services that will
72provide the depended-on values.
73
74This class consumes the L<Bread::Board::Traversable> role to retrieve
75services given their path.
76
77=head1 ATTRIBUTES
78
79=head2 C<service_path>
80
81The path to use (possibly relative to the dependency itself) to access
82the L</service>.
83
84=head2 C<service>
85
86The service this dependency points at. Usually built lazily from the
87L</service_path>, but could just be passed in to the constructor.
88
89=head2 C<service_name>
90
91Name of the L</service>, defaults to the last element of the
92L</service_path>.
93
94=head1 METHODS
95
96=head2 C<has_service_path>
97
98Predicate for the L</service_path> attribute.
99
100=head2 C<get>
101
102=head2 C<is_locked>
103
104=head2 C<lock>
105
106=head2 C<unlock>
107
108These methods are delegated to the L</service>.
109
110=head1 AUTHOR
111
112Stevan Little <stevan@iinteractive.com>
113
114=head1 BUGS
115
116Please report any bugs or feature requests on the bugtracker website
117https://github.com/stevan/BreadBoard/issues
118
119When submitting a bug or request, please include a test-file or a
120patch to an existing test-file that illustrates the bug or desired
121feature.
122
123=head1 COPYRIGHT AND LICENSE
124
125This software is copyright (c) 2019, 2017, 2016, 2015, 2014, 2013, 2011, 2009 by Infinity Interactive.
126
127This is free software; you can redistribute it and/or modify it under
128the same terms as the Perl 5 programming language system itself.
129
130=cut
131