eg/MyModel.pm

filter: Statementstmt 95.3% 62 / 65 Branchbran 53.3% 16 / 30 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 14 / 14 Podpod 0.0% 0 / 5 totaltotal 78.8% 97 / 123 CC 19 SCAR 14.7
CC
19
Cov
81%
comment_get
7.5
comment_cnt
6.1
comment_del
5.6
CRAP 4.3
« blib/lib/WWW/Suffit/Model.pm ↑ Summary
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
BranchTrueFalseTotal
unless $self->ping 0 1 1
47  
48 # Add
49 $self->query(DML_ADD,
50 $data{comment},
51 1 ▶ ) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->query("INSERT INTO `test`\n (`comment`)\nVALUES\n (?)\n", $data{"comment"}) or return 0 1 0 1
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
BranchTrueFalseTotal
unless $self->ping 0 1 1
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
BranchTrueFalseTotal
$self->query("UPDATE `test`\nSET `comment` = ?\nWHERE `id` = ?\n", $data{"comment"}, $data{"id"}) or return 0 1 0 1
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
BranchTrueFalseTotal
unless $self->ping 0 3 3
73 3 ▶ my $id = shift || 0;
Condition100%2/2
shift() || 0
l!l
21
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
74  
75 # Get all data as table
76 3 ▶ unless ($id) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id) 1 2 3
77 1 my $tbl = {};
78 1 ▶ if (my $res = $self->query(DML_ALL)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $res = $self->query("SELECT `id`,`comment`\nFROM `test`\nORDER BY `id` ASC\nLIMIT 100\n")) 1 0 1
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
BranchTrueFalseTotal
if (my $res = $self->query("SELECT `id`,`comment`\nFROM `test`\nWHERE `id` = ?\n", $id)) 2 0 2
87 2 my $r = $res->hash;
88 2 my %rec = ();
89 2 ▶ %rec = (%$r) if ref($r) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $r eq "HASH" 2 0 2
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
l!l
10
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
100 1 ▶ return 1 unless $id;
Branch: 1 branch
BranchTrueFalseTotal
unless $id 0 1 1
101 1 ▶ return 0 unless $self->ping;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->ping 0 1 1
102  
103 # Delete
104 1 ▶ $self->query(DML_DEL, $id) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->query("DELETE FROM `test`\nWHERE `id` = ?\n", $id) or return 0 1 0 1
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
BranchTrueFalseTotal
unless $self->ping 0 1 1
112  
113 1 ▶ if (my $res = $self->query(DML_CNT)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $res = $self->query("SELECT COUNT(`id`) AS `cnt`\nFROM `test`\n")) 1 0 1
114 1 my $r = $res->hash;
115 1 ▶ return $r->{cnt} || 0 if ref($r) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $r eq "HASH" 1 0 1
Condition50%1/2
$r->{'cnt'} || 0
l!l
10
MC/DC0%0/1
$r->{'cnt'} || 0
$r->{'cnt'}
Truth table50%1/2
A
A= $r->{'cnt'}
Aresult
11
00
116 }
117  
118 0 return 0;
119 }
120  
121 1 1;
122  
123 __DATA__
« blib/lib/WWW/Suffit/Model.pm ↑ Summary