| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Kelp::Module::Beam::Wire; |
|
2
|
|
|
|
|
|
|
$Kelp::Module::Beam::Wire::VERSION = '1.00'; |
|
3
|
1
|
|
|
1
|
|
515451
|
use Kelp::Base 'Kelp::Module'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
4
|
1
|
|
|
1
|
|
1486
|
use Beam::Wire; |
|
|
1
|
|
|
|
|
558145
|
|
|
|
1
|
|
|
|
|
244
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
sub build |
|
7
|
|
|
|
|
|
|
{ |
|
8
|
1
|
|
|
1
|
1
|
165
|
my ($self, %args) = @_; |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
|
|
7
|
my $wire = Beam::Wire->new(%args); |
|
11
|
1
|
|
50
|
|
|
8098
|
$wire->set($args{app_service} // 'app', $self->app); |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# register as a sub so that it is avaliable in class context |
|
14
|
1
|
|
|
3
|
|
170
|
$self->register(container => sub { $wire }); |
|
|
3
|
|
|
|
|
1964
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
50
|
return; |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
1; |
|
20
|
|
|
|
|
|
|
__END__ |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 NAME |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Kelp::Module::Beam::Wire - Beam::Wire dependency injection container for Kelp |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# in config |
|
30
|
|
|
|
|
|
|
modules => [qw(Beam::Wire)], |
|
31
|
|
|
|
|
|
|
modules_init => { |
|
32
|
|
|
|
|
|
|
'Beam::Wire' => { |
|
33
|
|
|
|
|
|
|
# optional, default is 'app' |
|
34
|
|
|
|
|
|
|
app_service => 'myapp', |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# other config for Beam::Wire constructor |
|
37
|
|
|
|
|
|
|
}, |
|
38
|
|
|
|
|
|
|
}, |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# in your application |
|
41
|
|
|
|
|
|
|
my $app = MyApp->container->get('myapp'); |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
This is a very straightforward module that registers the C<container> method in |
|
46
|
|
|
|
|
|
|
your Kelp app, accessing a constructed Beam::Wire object. |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 METHODS INTRODUCED TO KELP |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 container |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my $beam_wire = $kelp->container; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Returns the L<Beam::Wire> instance. |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
In addition to special behavior of the configuration fields listed below, all |
|
59
|
|
|
|
|
|
|
of the configuration from C<modules_init> is fed to L<Beam::Wire> constructor. |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 app_service |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
A name of the service which will hold the instance of the Kelp application |
|
64
|
|
|
|
|
|
|
itself. By default, value C<'app'> is used. |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Since Kelp is pretty much a singleton (unless you use L<Kelp/new_anon>), you |
|
67
|
|
|
|
|
|
|
can introduce this method for easy access to the application instance from the |
|
68
|
|
|
|
|
|
|
class name: |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub { |
|
71
|
|
|
|
|
|
|
shift->container->get('app') |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 CAVEATS |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Accessing the container from the class name won't work if you use |
|
78
|
|
|
|
|
|
|
L<Kelp/new_anon> to instantiate the application. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=over |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=item * L<Kelp>, the framework |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=item * L<Beam::Wire>, the dependency injection container |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=back |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Bartosz Jarzyna, E<lt>bbrtj.pro@gmail.comE<gt> |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Copyright (C) 2024 by Bartosz Jarzyna |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
99
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
|
102
|
|
|
|
|
|
|
|