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