1package Bread::Board::Service::Alias;
2our $AUTHORITY = 'cpan:STEVAN';
3# ABSTRACT: aliases another service
4$Bread::Board::Service::Alias::VERSION = '0.37';
5use Moose;
6
7use Try::Tiny;
8
9has aliased_from_path => (
10    is  => 'ro',
11    isa => 'Str',
12);
13
14has aliased_from => (
15    is      => 'ro',
16    does    => 'Bread::Board::Service',
17    lazy    => 1,
18    builder => '_build_aliased_from',
19    handles => ['get'], # is this sufficient?
20);
21
22with 'Bread::Board::Service';
23
24sub _build_aliased_from {
25    my $self = shift;
26
27    my $path = $self->aliased_from_path;
28    confess "Can't create an alias service without a service to alias from"
29        unless $path;
30
31    return try {
32        $self->fetch($path);
33    }
34    catch {
35        die "While resolving alias " . $self->name . ": $_";
36    };
37}
38
39__PACKAGE__->meta->make_immutable;
40
41no Moose; 1;
42
43__END__
44
45=pod
46
47=encoding UTF-8
48
49=head1 NAME
50
51Bread::Board::Service::Alias - aliases another service
52
53=head1 VERSION
54
55version 0.37
56
57=head1 DESCRIPTION
58
59This L<service|Bread::Board::Service> class implements
60L<aliases|Bread::Board/alias ($service_name, $service_path,
61%service_description)>.
62
63=head1 ATTRIBUTES
64
65=head2 C<aliased_from_path>
66
67Read-only string attribute, the path of the service this alias refers
68to (it can be an alias itself)
69
70=head2 C<aliased_from>
71
72Lazy read-only attribute, built by calling L<<
73C<fetch>|Bread::Board::Traversable/fetch >> on this service using the
74L</aliased_from_path> as path to fetch
75
76=head1 AUTHOR
77
78Stevan Little <stevan@iinteractive.com>
79
80=head1 BUGS
81
82Please report any bugs or feature requests on the bugtracker website
83https://github.com/stevan/BreadBoard/issues
84
85When submitting a bug or request, please include a test-file or a
86patch to an existing test-file that illustrates the bug or desired
87feature.
88
89=head1 COPYRIGHT AND LICENSE
90
91This software is copyright (c) 2019, 2017, 2016, 2015, 2014, 2013, 2011, 2009 by Infinity Interactive.
92
93This is free software; you can redistribute it and/or modify it under
94the same terms as the Perl 5 programming language system itself.
95
96=cut
97