| 1 | package Mojolicious::Service; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use Mojo::Base -base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use Carp qw/cluck confess/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | has [qw/dbi models app c dmn parent/]; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 0 | ▶ | sub model{ | ||||||||||||||||||||||||||
|
Subroutine
model: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 8 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # Check model existence | ||||||||||||||||||||||||||||
| 11 | 0 | ▶ | cluck qq{model "$name" is not yet created } unless($self->models && $self->models->{$name}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->models and $self->models->{$name}
MC/DC0%0/2
$self->models and $self->models->{$name}
$self->models
$self->models->{$name}
Truth table0%0/3
A and B
A= $self->modelsB= $self->models->{$name}
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | # Get model | ||||||||||||||||||||||||||||
| 14 | 0 | return $self->models->{$name}; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub service{ | ||||||||||||||||||||||||||
|
Subroutine
service: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 19 | 0 | ▶ | return $self->parent->service(@_) if($self->parent); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 0 | confess "require [parent] field"; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | ## 调用 model 层的 create 方法 | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | sub mcreate{ | ||||||||||||||||||||||||||
|
Subroutine
mcreate: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 26 | 0 | my $table = $self->dmn; | |||||||||||||||||||||||||||
| 27 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 28 | 0 | my $obj = $model->create(@_); | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | return undef unless($obj && $obj->{object}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and $obj->{"object"}
MC/DC0%0/2
$obj and $obj->{"object"}
$obj
$obj->{"object"}
Truth table0%0/3
A and B
A= $objB= $obj->{"object"}
| |||||||||||||||||||||||||||||
| 30 | 0 | return $obj->{object}; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | ## 调用 model 层的 edit 方法 | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub medit{ | ||||||||||||||||||||||||||
|
Subroutine
medit: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 36 | 0 | my $table = $self->dmn; | |||||||||||||||||||||||||||
| 37 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 38 | 0 | my $obj = $model->edit(@_); | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | return undef unless($obj && $obj->{rows}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and $obj->{"rows"}
MC/DC0%0/2
$obj and $obj->{"rows"}
$obj
$obj->{"rows"}
Truth table0%0/3
A and B
A= $objB= $obj->{"rows"}
| |||||||||||||||||||||||||||||
| 40 | 0 | return $obj->{rows}; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | ## 调用 model 层的 remove 方法 | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub mremove{ | ||||||||||||||||||||||||||
|
Subroutine
mremove: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 46 | 0 | my $table = $self->dmn; | |||||||||||||||||||||||||||
| 47 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 48 | 0 | my $obj = $model->remove(@_); | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | return undef unless($obj && $obj->{rows}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and $obj->{"rows"}
MC/DC0%0/2
$obj and $obj->{"rows"}
$obj
$obj->{"rows"}
Truth table0%0/3
A and B
A= $objB= $obj->{"rows"}
| |||||||||||||||||||||||||||||
| 50 | 0 | return $obj->{rows}; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | ## 调用 model 层的 sremove 方法 | ||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub msremove{ | ||||||||||||||||||||||||||
|
Subroutine
msremove: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 0 | my $table = $self->dmn; | |||||||||||||||||||||||||||
| 57 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 58 | 0 | my $obj = $model->sremove(@_); | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | return undef unless($obj && $obj->{rows}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and $obj->{"rows"}
MC/DC0%0/2
$obj and $obj->{"rows"}
$obj
$obj->{"rows"}
Truth table0%0/3
A and B
A= $objB= $obj->{"rows"}
| |||||||||||||||||||||||||||||
| 60 | 0 | return $obj->{rows}; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | ## 调用 model 层的 count 方法 | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | sub mcount{ | ||||||||||||||||||||||||||
|
Subroutine
mcount: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 67 | 0 | my $table = $self->dmn; | |||||||||||||||||||||||||||
| 68 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 69 | 0 | return $model->count(@_); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub AUTOLOAD{ | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=54 SCAR=79.6
| |||||||||||||||||||||||||||||
| 75 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 76 | 0 | my ($package, $method) = our $AUTOLOAD =~ /^(.+)::(.+)$/; | |||||||||||||||||||||||||||
| 77 | 2 | ▶ | no strict qw/refs/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | ## 在哪个包里调用的这个方法 | ||||||||||||||||||||||||||||
| 80 | 0 | my $pkg = caller(0); | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | ## 调用 model 层的create方法 | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if($method =~ /^mcreate_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | my $table = $1; | |||||||||||||||||||||||||||
| 85 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 86 | 0 | my $obj = $model->create(@_); | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | return undef unless($obj && $obj->{object}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and $obj->{"object"}
MC/DC0%0/2
$obj and $obj->{"object"}
$obj
$obj->{"object"}
Truth table0%0/3
A and B
A= $objB= $obj->{"object"}
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | return $pkg->isa(__PACKAGE__) ? $obj : $obj->{object}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | ## 调用 model 层的edit方法 | ||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if($method =~ /^medit_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 0 | my $table = $1; | |||||||||||||||||||||||||||
| 95 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 96 | 0 | my $obj = $model->edit(@_); | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | return undef unless($obj && $obj->{rows}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and $obj->{"rows"}
MC/DC0%0/2
$obj and $obj->{"rows"}
$obj
$obj->{"rows"}
Truth table0%0/3
A and B
A= $objB= $obj->{"rows"}
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return $pkg->isa(__PACKAGE__) ? $obj : $obj->{rows}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | ## 调用 model 层的remove方法 | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if($method =~ /^mremove_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 104 | 0 | my $table = $1; | |||||||||||||||||||||||||||
| 105 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 106 | 0 | my $obj = $model->remove(@_); | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | return undef unless($obj && $obj->{rows}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and $obj->{"rows"}
MC/DC0%0/2
$obj and $obj->{"rows"}
$obj
$obj->{"rows"}
Truth table0%0/3
A and B
A= $objB= $obj->{"rows"}
| |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | return $pkg->isa(__PACKAGE__) ? $obj : $obj->{rows}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | ## 调用 model 层的sremove方法 | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if($method =~ /^msremove_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 0 | my $table = $1; | |||||||||||||||||||||||||||
| 115 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 116 | 0 | my $obj = $model->sremove(@_); | |||||||||||||||||||||||||||
| 117 | 0 | ▶ | return undef unless($obj && $obj->{rows}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and $obj->{"rows"}
MC/DC0%0/2
$obj and $obj->{"rows"}
$obj
$obj->{"rows"}
Truth table0%0/3
A and B
A= $objB= $obj->{"rows"}
| |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | return $pkg->isa(__PACKAGE__) ? $obj : $obj->{rows}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | ## 调用 model 层的 count 方法 | ||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if($method =~ /^mcount_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 0 | my $table = $1; | |||||||||||||||||||||||||||
| 124 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 125 | 0 | return $model->count(@_); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | ## get_by_字段名 | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if($method =~ /^get_by_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 0 | my $table = $self->dmn; | |||||||||||||||||||||||||||
| 131 | 0 | my $field = $1; | |||||||||||||||||||||||||||
| 132 | 0 | my $mmethod = "get_by_" . $field; | |||||||||||||||||||||||||||
| 133 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 134 | 0 | ▶ | cluck "the model [$table] if not found!" unless($model); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | my $obj = $model->$mmethod(@_); | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | return undef unless($obj && $obj->{$model->name}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and $$obj{$model->name}
MC/DC0%0/2
$obj and $$obj{$model->name}
$obj
$$obj{$model->name}
Truth table0%0/3
A and B
A= $objB= $$obj{$model->name}
| |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | return $pkg->isa(__PACKAGE__) ? $obj : $field eq "id" ? $obj->{$model->name} : $obj->{list}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | ## get_表名_by_字段名 | ||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if($method =~ /^get_(.+)_by_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | my $table = $1; | |||||||||||||||||||||||||||
| 144 | 0 | my $field = $2; | |||||||||||||||||||||||||||
| 145 | 0 | my $mmethod = "get_by_" . $field; | |||||||||||||||||||||||||||
| 146 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 147 | 0 | ▶ | cluck "the model [$table] if not found!" unless($model); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | my $obj = $model->$mmethod(@_); | |||||||||||||||||||||||||||
| 150 | 0 | ▶ | return undef unless($obj && $obj->{$model->name}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and $$obj{$model->name}
MC/DC0%0/2
$obj and $$obj{$model->name}
$obj
$$obj{$model->name}
Truth table0%0/3
A and B
A= $objB= $$obj{$model->name}
| |||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return $pkg->isa(__PACKAGE__) ? $obj : $field eq "id" ? $obj->{$model->name} : $obj->{list}; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | ## remove_by_字段名 | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | if($method =~ /^remove_by_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 0 | my $table = $self->dmn; | |||||||||||||||||||||||||||
| 158 | 0 | my $field = $1; | |||||||||||||||||||||||||||
| 159 | 0 | my $mmethod = "remove_by_" . $field; | |||||||||||||||||||||||||||
| 160 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 161 | 0 | ▶ | cluck "the model [$table] if not found!" unless($model); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | my $obj = $model->$mmethod(@_); | |||||||||||||||||||||||||||
| 164 | 0 | ▶ | return undef unless($obj && defined $obj->{rows}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and defined $obj->{"rows"}
MC/DC0%0/2
$obj and defined $obj->{"rows"}
$obj
defined $obj->{"rows"}
Truth table0%0/3
A and B
A= $objB= defined $obj->{"rows"}
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | return $pkg->isa(__PACKAGE__) ? $obj : $obj->{rows}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | ## remove_表名_by_字段名 | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | if($method =~ /^remove_(.+)_by_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | 0 | my $table = $1; | |||||||||||||||||||||||||||
| 171 | 0 | my $field = $2; | |||||||||||||||||||||||||||
| 172 | 0 | my $mmethod = "remove_by_" . $field; | |||||||||||||||||||||||||||
| 173 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | cluck "the model [$table] if not found!" unless($model); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | my $obj = $model->$mmethod(@_); | |||||||||||||||||||||||||||
| 177 | 0 | ▶ | return undef unless($obj && defined $obj->{rows}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and defined $obj->{"rows"}
MC/DC0%0/2
$obj and defined $obj->{"rows"}
$obj
defined $obj->{"rows"}
Truth table0%0/3
A and B
A= $objB= defined $obj->{"rows"}
| |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | return $pkg->isa(__PACKAGE__) ? $obj : $obj->{rows}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | ## sremove_表名_by_字段名 | ||||||||||||||||||||||||||||
| 184 | 0 | ▶ | if($method =~ /^sremove_by_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | 0 | my $table = $self->dmn; | |||||||||||||||||||||||||||
| 186 | 0 | my $field = $1; | |||||||||||||||||||||||||||
| 187 | 0 | my $mmethod = "sremove_by_" . $field; | |||||||||||||||||||||||||||
| 188 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 189 | 0 | ▶ | cluck "the model [$table] if not found!" unless($model); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | my $obj = $model->$mmethod(@_); | |||||||||||||||||||||||||||
| 192 | 0 | ▶ | return undef unless($obj && defined $obj->{rows}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and defined $obj->{"rows"}
MC/DC0%0/2
$obj and defined $obj->{"rows"}
$obj
defined $obj->{"rows"}
Truth table0%0/3
A and B
A= $objB= defined $obj->{"rows"}
| |||||||||||||||||||||||||||||
| 193 | 0 | ▶ | return $pkg->isa(__PACKAGE__) ? $obj : $obj->{rows}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | ## sremove_表名_by_字段名 | ||||||||||||||||||||||||||||
| 197 | 0 | ▶ | if($method =~ /^sremove_(.+)_by_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 0 | my $table = $1; | |||||||||||||||||||||||||||
| 199 | 0 | my $field = $2; | |||||||||||||||||||||||||||
| 200 | 0 | my $mmethod = "sremove_by_" . $field; | |||||||||||||||||||||||||||
| 201 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 202 | 0 | ▶ | cluck "the model [$table] if not found!" unless($model); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 0 | my $obj = $model->$mmethod(@_); | |||||||||||||||||||||||||||
| 205 | 0 | ▶ | return undef unless($obj && defined $obj->{rows}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$obj and defined $obj->{"rows"}
MC/DC0%0/2
$obj and defined $obj->{"rows"}
$obj
defined $obj->{"rows"}
Truth table0%0/3
A and B
A= $objB= defined $obj->{"rows"}
| |||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return $pkg->isa(__PACKAGE__) ? $obj : $obj->{rows}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | ## count_表名_by_字段名 | ||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if($method =~ /^count_by_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | 0 | my $table = $self->dmn; | |||||||||||||||||||||||||||
| 213 | 0 | my $field = $2; | |||||||||||||||||||||||||||
| 214 | 0 | my $mmethod = "count_by_" . $field; | |||||||||||||||||||||||||||
| 215 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 216 | 0 | ▶ | cluck "the model [$table] if not found!" unless($model); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 0 | return $model->$mmethod(@_); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | ## count_表名_by_字段名 | ||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if($method =~ /^count_(.+)_by_(.+)$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 224 | 0 | my $table = $1; | |||||||||||||||||||||||||||
| 225 | 0 | my $field = $2; | |||||||||||||||||||||||||||
| 226 | 0 | my $mmethod = "count_by_" . $field; | |||||||||||||||||||||||||||
| 227 | 0 | my $model = $self->model($table); | |||||||||||||||||||||||||||
| 228 | 0 | ▶ | cluck "the model [$table] if not found!" unless($model); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | 0 | return $model->$mmethod(@_); | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | confess qq{Can't locate object method "$method" via package "$package"} | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | =encoding utf8 | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | =head1 NAME | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | Mojolicious::Service - Mojolicious框架中所有Service的基类(具体的Service需要用户实现)! | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | use Mojolicious::Service | ||||||||||||||||||||||||||||
| 248 | my $service = Mojolicious::Service->new({ | ||||||||||||||||||||||||||||
| 249 | dbi=>DBIx::Custom->new(), | ||||||||||||||||||||||||||||
| 250 | models=>{} | ||||||||||||||||||||||||||||
| 251 | }); | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | my $user->some_mothed(arg1,arg2,……); | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | Mojolicious框架中所有Service的基类(具体的Service需要用户实现)! | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | =head2 dbi | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | dbi 是为service提供数据库操作接口的对象。 | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | =head2 models | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | models 是为service提供数据模型操作接口的对象。 | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =head2 app | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 当前应用程序的引用,通常是Mojolicious对象。 | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | =head2 c | ||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 当前控制器的引用,通常是Mojolicious::Controller子类的对象。 | ||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | =head1 METHODS | ||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||
| 283 | =head2 model | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 根据model的名称从 models 属性中获取model。 | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | wfso, C<< <461663376@qq.com> >> | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | =head1 BUGS | ||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||
| 294 | Please report any bugs or feature requests to C<bug-mojolicious-Services at rt.cpan.org>, or through | ||||||||||||||||||||||||||||
| 295 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Mojolicious-Services>. I will be notified, and then you'll | ||||||||||||||||||||||||||||
| 296 | automatically be notified of progress on your bug as I make changes. | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | perldoc Mojolicious::Service | ||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | You can also look for information at: | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | =over 4 | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | =item * RT: CPAN's request tracker (report bugs here) | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Mojolicious-Services> | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | L<http://annocpan.org/dist/Mojolicious-Services> | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | L<http://cpanratings.perl.org/d/Mojolicious-Services> | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | L<http://search.cpan.org/dist/Mojolicious-Services/> | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | =back | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | =cut | ||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 2 | 1; # End of Mojolicious::Service | |||||||||||||||||||||||||||