File Coverage

eg/MyModel.pm
Criterion Covered Total %
statement 61 64 95.3
branch 16 30 53.3
condition 4 6 66.6
subroutine 14 14 100.0
pod 0 5 0.0
total 95 119 79.8


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