line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Service; |
2
|
1
|
|
|
1
|
|
1069
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
3
|
1
|
|
|
1
|
|
609
|
use Mojolicious::ServiceManage; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
20
|
use Scalar::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
234
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub register{ |
8
|
0
|
|
|
0
|
1
|
|
my ($self, $app, $conf) = @_; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Merge config |
11
|
0
|
0
|
|
|
|
|
$conf = {%{$conf},%{$app->config->{service_config}}} if($app->config->{service_config}); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
$conf->{app} = $app; |
13
|
0
|
0
|
|
|
|
|
if($app->renderer->get_helper("dbi")){ |
14
|
0
|
|
0
|
|
|
|
$conf->{dbi} ||= $app->dbi; |
15
|
0
|
0
|
|
|
|
|
if($app->dbi->can("models")){ |
16
|
0
|
|
0
|
|
|
|
$conf->{models} ||= $app->dbi->models; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
0
|
0
|
|
|
|
|
if($app->renderer->get_helper("models")){ |
21
|
0
|
|
0
|
|
|
|
$conf->{models} ||= $app->models; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# create service management |
26
|
0
|
|
|
|
|
|
my $sm = Mojolicious::ServiceManage->new($conf); |
27
|
0
|
|
|
|
|
|
Scalar::Util::weaken $sm->{app}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# create helper for service |
30
|
|
|
|
|
|
|
$app->helper(service=>sub{ |
31
|
0
|
|
|
0
|
|
|
my ($c,$name) = @_; |
32
|
0
|
|
|
|
|
|
my $service = $sm->service($name); |
33
|
0
|
|
|
|
|
|
return $service; |
34
|
|
|
|
|
|
|
} |
35
|
0
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=encoding utf8 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 NAME |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Mojolicious::Plugin::Service - 向Mojolicious框架中引入Service管理器的插件! |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
向Mojolicious框架中引入Service管理器的插件。 |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Mojolicious |
55
|
|
|
|
|
|
|
$app->plugin('Service',$config); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Mojolicious::Lite |
58
|
|
|
|
|
|
|
plugin('DefaultHelpers',$config); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Mojolicious::Plugin::Service inherits all methods from Mojolicious::Plugin and implements the following new ones. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 register |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
$plugin->register(Mojolicious->new,$config); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Register helper in Mojolicious application named service. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 config Option |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
register 方法中除接受Mojolicious对象为参数外,还接受一个config参数。这个config参数是必须是一个hashref。 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
dbi=>DBIx::Custom->new(), |
79
|
|
|
|
|
|
|
models=>DBIx::Custom->new->models, |
80
|
|
|
|
|
|
|
namespaces=>s["Mojolicious::Service"], |
81
|
|
|
|
|
|
|
lazy => 1 |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 dbi |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
dbi 是为service提供数据库操作接口的对象。 |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 models |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
models 是为service提供数据模型操作接口的对象。 |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head2 namespace |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
namespace 用于说明service类所在的命名空间,这个属性的值是一个arrayref 类型的值,支持在多个命名空间中查找service。 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 lazy |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
用于说明是否启用懒加载模式。 |
103
|
|
|
|
|
|
|
如果值为true则启用懒加载,只有在实际请求一个service时才加载其类并实例化一个service对象。 |
104
|
|
|
|
|
|
|
如果为flase则在创建Mojolicious::ServiceManage时加载所有service类并实例化成对象。 |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 AUTHOR |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
wfso, C<< <461663376@qq.com> >> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 BUGS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
115
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
116
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 SUPPORT |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
perldoc Mojolicious::Plugin::Service |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
You can also look for information at: |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=over 4 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker (report bugs here) |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
L |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * CPAN Ratings |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * Search CPAN |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=back |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=cut |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; # End of Mojolicious::Plugin::Service |