UserMessage.pm

filter: Statementstmt 21.4% 15 / 70 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 15 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 31.2% 5 / 16 Podpod n/a totaltotal 15.8% 20 / 126 CC 16 SCAR 24.2
CC
16
Cov
15%
delete
20.0
post
20.0
retrieve_obj_list
20.0
CRAP 11.3
↑ Summary UserMessage/CDBI.pm »
1 package Kwiki::UserMessage;
2 1 ▶use Kwiki::Plugin qw(-Base -XXX);
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use mixin 'Kwiki::Installer';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 our $VERSION = '0.02';
5  
6 const class_id => 'user_message';
7 const class_title => 'Kwiki User Message';
8 const cgi_class => 'Kwiki::UserMessage::CGI';
9  
10 const css_file => 'user_message.css';
11 const javascript_file => 'user_message.js';
12  
13 field cdbi => -init => '$self->hub->cdbi';
14  
15 field 'display_msg';
16  
17 0 ▶sub register {
Subroutine register: not called CC=1 SCAR=6.9
18 0 my $registry = shift;
19 0 $registry->add(action => 'user_message');
20 0 $registry->add(toolbar => 'user_message',
21 template => 'user_message_toolbar.html');
22 }
23  
24 0 ▶sub dbinit {
Subroutine dbinit: not called CC=2 SCAR=17.9
25 0 my $dbpath = io->catfile($self->plugin_directory,"data.sqlt");
26 0 my $db = $self->hub->cdbi;
27 0 $db->base('Kwiki::UserMessage::CDBI');
28 0 $db->connection("dbi:SQLite:".$dbpath->name);
29 0 ▶ $db->dbinit unless $dbpath->exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $dbpath->exists 0 0 0
30 }
31  
32 0 ▶sub user_message {
Subroutine user_message: not called CC=3 SCAR=24.8
33 0 $self->dbinit;
34 0 ▶ my $mode = $self->cgi->run_mode || 'list';
Condition0%0/2
$self->cgi->run_mode || 'list'
l!l
00
MC/DC0%0/1
$self->cgi->run_mode || 'list'
$self->cgi->run_mode
Truth table0%0/2
A
A= $self->cgi->run_mode
Aresult
11
00
35 0 ▶ $self->$mode if $self->can($mode);
Branch: 1 branch
BranchTrueFalseTotal
if $self->can($mode) 0 0 0
36 0 $self->render_screen;
37 }
38  
39 0 ▶sub list {}
Subroutine list: not called CC=1 SCAR=6.9
40 0 ▶sub compose {}
Subroutine compose: not called CC=1 SCAR=6.9
41  
42 0 ▶sub delete {
Subroutine delete: not called CC=4 SCAR=30.0
43 0 ▶ my $id = shift || $self->cgi->id;
Condition0%0/3
shift() || $self->cgi->id
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->cgi->id
shift() $self->cgi->id
Truth table0%0/3
A || B
A= shift()B= $self->cgi->id
ABresult
1X1
011
000
44 0 ▶ $self->delete_message($id) if $id;
Branch: 1 branch
BranchTrueFalseTotal
if $id 0 0 0
45  
46 0 my $obj = $self->cdbi->retrieve($id);
47 0 ▶ $obj->delete if $obj;
Branch: 1 branch
BranchTrueFalseTotal
if $obj 0 0 0
48 }
49  
50 0 ▶sub post {
Subroutine post: not called CC=4 SCAR=30.0
51 0 my $caller_sub = (caller(1))[3];
52 0 ▶ if($caller_sub eq 'Kwiki::UserMessage::user_message') {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller_sub eq 'Kwiki::UserMessage::user_message') { } 0 0 0
53 0 ▶ if($self->post($self->users->current->name,
Branch: 1 branch
BranchTrueFalseTotal
if ($self->post($self->users->current->name, $self->cgi->to, $self->cgi->subject, $self->cgi->body)) { } 0 0 0
54 $self->cgi->to,
55 $self->cgi->subject,
56 $self->cgi->body)) {
57 0 $self->display_msg("Message Delivered");
58 } else {
59 0 $self->display_msg("Delivery Error");
60 }
61 } else {
62 0 my ($sender,$receiver,$subject,$body) = @_;
63 0 ▶ my $vars = {
Condition0%0/2
$self->cdbi->maximum_value_of('id') || 1
l!l
00
MC/DC0%0/1
$self->cdbi->maximum_value_of('id') || 1
$self->cdbi->maximum_value_of('id')
Truth table0%0/2
A
A= $self->cdbi->maximum_value_of('id')
Aresult
11
00
64 id => $self->cdbi->maximum_value_of("id")||0 + 1,
65 sender => $sender,
66 receiver => $receiver,
67 subject => $subject,
68 body => $body,
69 ts => scalar(localtime)
70 };
71 0 $self->cdbi->create($vars);
72 }
73 }
74  
75 0 ▶sub message_list {
Subroutine message_list: not called CC=2 SCAR=17.9
76 0 ▶ my $user = shift || $self->users->current->name;
Condition0%0/3
shift() || $self->users->current->name
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->users->current->name
shift() $self->users->current->name
Truth table0%0/3
A || B
A= shift()B= $self->users->current->name
ABresult
1X1
011
000
77 0 my $it = $self->cdbi->search( receiver => $user );
78 0 my @obj = $self->retrieve_obj_list($it);
79 0 return \@obj;
80 }
81  
82 0 ▶sub load_message {
Subroutine load_message: not called CC=1 SCAR=6.9
83 0 my $id = shift;
84 0 $self->retrieve_obj($self->cdbi->retrieve($id), $self->cdbi->columns());
85 }
86  
87 0 ▶sub retrieve_obj_list {
Subroutine retrieve_obj_list: not called CC=4 SCAR=30.0
88 0 ▶ my $it = shift || return;
Condition0%0/2
shift() || (return)
l!l
00
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
89 0 ▶ my $entity = shift || $self->cdbi;
Condition0%0/3
shift() || $self->cdbi
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->cdbi
shift() $self->cdbi
Truth table0%0/3
A || B
A= shift()B= $self->cdbi
ABresult
1X1
011
000
90 0 my @objs;
91 0 my @columns = $entity->columns();
92 0 ▶ while(my $obj = $it->next) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $obj = $it->next) 0 0 0
93 0 push @objs, $self->retrieve_obj($obj,@columns);
94 }
95 0 return @objs;
96 }
97  
98 0 ▶sub retrieve_obj {
Subroutine retrieve_obj: not called CC=3 SCAR=24.8
99 0 my ($obj,@columns) = @_;
100 0 ▶ return unless ref($obj);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $obj 0 0 0
101 0 my $var;
102 0 for(@columns) {
103 0 $var->{$_} = $self->utf8_decode($obj->$_);
104 }
105 0 $var->{time} = $var->{ts};
106 0 return $var;
107 }
108  
109 package Kwiki::UserMessage::CGI;
110 1 ▶use base 'Kwiki::CGI';
Subroutine BEGIN: called CC=1 SCAR=0.0
111  
112 cgi 'run_mode';
113 cgi 'id';
114 cgi 'to';
115 cgi 'body';
116 cgi 'subject';
117  
118 package Kwiki::UserMessage;
119  
120 __DATA__
↑ Summary UserMessage/CDBI.pm »