blib/lib/Mojolicious/Plugin/DBI.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
↑ Summary
1 package Mojolicious::Plugin::DBI;
2 0 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=2.6
3  
4 # 加载 DBIx-Custom
5 use DBIx::Custom;
6  
7 #------------------------------------------------------------------------------
8 # Mojo DBI 版本信息
9 #------------------------------------------------------------------------------
10 our $VERSION = '0.0.1';
11  
12 #------------------------------------------------------------------------------
13 # Mojo DBI 插件入口, $conf 用来接收变量
14 #------------------------------------------------------------------------------
15 sub register {
16 my ( $self, $app, $conf ) = @_;
17  
18 # 提取 DSN 配置参数
19 my $dsn = $conf->{"dsn"} or die ": Parameter 'dsn' missing";
20 my $username = $conf->{"username"};
21 my $password = $conf->{"password"};
22 my $options = $conf->{"options"};
23  
24 $app->log->debug($username);
25 $app->log->debug($password);
26 $app->log->debug($dsn);
27 # 尝试 连接 数据库
28 my $connect = DBIx::Custom->connect( $dsn, $username, $password, $options );
29 $connect->quote('');
30  
31 # 注册别名,可在控制器、App和模板内调用
32 my $short_name = $conf->{"helper"} || "dbi";
33 $app->helper(
34 $short_name => sub {
35 my $self = shift;
36 return $connect;
37 }
38 );
39 }
40  
41 1;
42  
↑ Summary