| 1 | package MyModel; | ||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use parent qw/WWW::Suffit::Model/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use constant DML_ADD => <<'DML'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | INSERT INTO `test` | ||||||||||||||||||||
| 9 | (`comment`) | ||||||||||||||||||||
| 10 | VALUES | ||||||||||||||||||||
| 11 | (?) | ||||||||||||||||||||
| 12 | DML | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 1 | ▶ | use constant DML_GET => <<'DML'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | SELECT `id`,`comment` | ||||||||||||||||||||
| 16 | FROM `test` | ||||||||||||||||||||
| 17 | WHERE `id` = ? | ||||||||||||||||||||
| 18 | DML | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 1 | ▶ | use constant DML_SET => <<'DML'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | UPDATE `test` | ||||||||||||||||||||
| 22 | SET `comment` = ? | ||||||||||||||||||||
| 23 | WHERE `id` = ? | ||||||||||||||||||||
| 24 | DML | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 1 | ▶ | use constant DML_DEL => <<'DML'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | DELETE FROM `test` | ||||||||||||||||||||
| 28 | WHERE `id` = ? | ||||||||||||||||||||
| 29 | DML | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 1 | ▶ | use constant DML_ALL => <<'DML'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | SELECT `id`,`comment` | ||||||||||||||||||||
| 33 | FROM `test` | ||||||||||||||||||||
| 34 | ORDER BY `id` ASC | ||||||||||||||||||||
| 35 | LIMIT 100 | ||||||||||||||||||||
| 36 | DML | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 1 | ▶ | use constant DML_CNT => <<'DML'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | SELECT COUNT(`id`) AS `cnt` | ||||||||||||||||||||
| 40 | FROM `test` | ||||||||||||||||||||
| 41 | DML | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 1 | ▶ | sub comment_add { | ||||||||||||||||||
|
Subroutine
comment_add: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||
| 44 | 1 | my $self = shift; | |||||||||||||||||||
| 45 | 1 | my %data = @_; | |||||||||||||||||||
| 46 | 1 | ▶ | return unless $self->ping; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | # Add | ||||||||||||||||||||
| 49 | $self->query(DML_ADD, | ||||||||||||||||||||
| 50 | $data{comment}, | ||||||||||||||||||||
| 51 | 1 | ▶ | ) or return 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | # Ok | ||||||||||||||||||||
| 54 | 1 | return 1; | |||||||||||||||||||
| 55 | } | ||||||||||||||||||||
| 56 | 1 | ▶ | sub comment_set { | ||||||||||||||||||
|
Subroutine
comment_set: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||
| 57 | 1 | my $self = shift; | |||||||||||||||||||
| 58 | 1 | my %data = @_; | |||||||||||||||||||
| 59 | 1 | ▶ | return 0 unless $self->ping; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | # Set by id or num | ||||||||||||||||||||
| 62 | $self->query(DML_SET, | ||||||||||||||||||||
| 63 | $data{comment}, | ||||||||||||||||||||
| 64 | $data{id}, | ||||||||||||||||||||
| 65 | 1 | ▶ | ) or return 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # Ok | ||||||||||||||||||||
| 68 | 1 | return 1; | |||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | 3 | ▶ | sub comment_get { | ||||||||||||||||||
|
Subroutine
comment_get: called CC=7 SCAR=20.2
Pod
undocumented
| |||||||||||||||||||||
| 71 | 3 | my $self = shift; | |||||||||||||||||||
| 72 | 3 | ▶ | return () unless $self->ping; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 73 | 3 | ▶ | my $id = shift || 0; | ||||||||||||||||||
|
Condition100%2/2
shift() || 0
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | # Get all data as table | ||||||||||||||||||||
| 76 | 3 | ▶ | unless ($id) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 77 | 1 | my $tbl = {}; | |||||||||||||||||||
| 78 | 1 | ▶ | if (my $res = $self->query(DML_ALL)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 79 | 1 | $tbl = $res->hashes; | |||||||||||||||||||
| 80 | 1 | return (@$tbl); | |||||||||||||||||||
| 81 | } | ||||||||||||||||||||
| 82 | 0 | return (); # No data or error | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | # Get data | ||||||||||||||||||||
| 86 | 2 | ▶ | if (my $res = $self->query(DML_GET, $id)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 87 | 2 | my $r = $res->hash; | |||||||||||||||||||
| 88 | 2 | my %rec = (); | |||||||||||||||||||
| 89 | 2 | ▶ | %rec = (%$r) if ref($r) eq 'HASH'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | # Ok | ||||||||||||||||||||
| 91 | 2 | return %rec; | |||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | # No data or error | ||||||||||||||||||||
| 95 | 0 | return (); | |||||||||||||||||||
| 96 | } | ||||||||||||||||||||
| 97 | 1 | ▶ | sub comment_del { | ||||||||||||||||||
|
Subroutine
comment_del: called CC=5 SCAR=17.2
Pod
undocumented
| |||||||||||||||||||||
| 98 | 1 | my $self = shift; | |||||||||||||||||||
| 99 | 1 | ▶ | my $id = shift || 0; | ||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 100 | 1 | ▶ | return 1 unless $id; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 101 | 1 | ▶ | return 0 unless $self->ping; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | # Delete | ||||||||||||||||||||
| 104 | 1 | ▶ | $self->query(DML_DEL, $id) or return 0; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | # Ok | ||||||||||||||||||||
| 107 | 1 | return 1; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | 1 | ▶ | sub comment_cnt { | ||||||||||||||||||
|
Subroutine
comment_cnt: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||
| 110 | 1 | my $self = shift; | |||||||||||||||||||
| 111 | 1 | ▶ | return 0 unless $self->ping; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 1 | ▶ | if (my $res = $self->query(DML_CNT)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 114 | 1 | my $r = $res->hash; | |||||||||||||||||||
| 115 | 1 | ▶ | return $r->{cnt} || 0 if ref($r) eq 'HASH'; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$r->{'cnt'} || 0
MC/DC0%0/1
$r->{'cnt'} || 0
$r->{'cnt'}
Truth table50%1/2
A
A= $r->{'cnt'}
| |||||||||||||||||||||
| 116 | } | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | 0 | return 0; | |||||||||||||||||||
| 119 | } | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | 1 | 1; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | __DATA__ | ||||||||||||||||||||