lib/Kwiki/PagePrivacy.pm

filter: Statementstmt 17.8% 13 / 73 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 35.7% 5 / 14 Podpod n/a totaltotal 14.4% 18 / 125 CC 17 SCAR 25.8
CC
17
Cov
12%
page_privacy_set
30.0
page_privacy
20.0
is_readable
12.0
CRAP 13.2
↑ Summary
1 package Kwiki::PagePrivacy;
2 1 ▶use Kwiki::Plugin -Base;
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.10';
5  
6 const class_id => 'page_privacy';
7 const cgi_class => 'Kwiki::PagePrivacy::CGI';
8 const config_file => 'page_privacy.yaml';
9  
10 0 ▶sub register {
Subroutine register: not called CC=1 SCAR=6.9
11 0 my $registry = shift;
12 0 $registry->add(action => 'page_privacy_set');
13 0 $registry->add(widget => 'page_privacy_select',
14 template => 'page_privacy_select.html',
15 show_for => 'display',
16 );
17 0 $registry->add(hook => 'page:is_readable',
18 post => 'is_readable',
19 );
20 0 $registry->add(hook => 'page:is_writable',
21 post => 'is_writable',
22 );
23 0 $registry->add(hook => 'page:to_html',
24 pre => 'linked_page_formatter',
25 );
26 }
27  
28 0 ▶sub linked_page_formatter {
Subroutine linked_page_formatter: not called CC=2 SCAR=17.9
29 0 my $page = $self;
30 0 ▶ return unless io($page->file_path)->is_link;
Branch: 1 branch
BranchTrueFalseTotal
unless io($page->file_path)->is_link 0 0 0
31 0 my $hook = pop;
32 0 $hook->cancel;
33 0 return '<pre>' . $self->html_escape($page->content) . '</pre>';
34 }
35  
36 0 ▶sub is_readable {
Subroutine is_readable: not called CC=3 SCAR=24.8
37 0 my $page = $self;
38 0 my $hook = pop;
39 0 ▶ return unless $hook->returned_true;
Branch: 1 branch
BranchTrueFalseTotal
unless $hook->returned_true 0 0 0
40 0 $self = $self->hub->page_privacy;
41 0 my $privacy = $self->page_privacy($page);
42 0 ▶ return 1 unless $privacy eq 'private';
Branch: 1 branch
BranchTrueFalseTotal
unless $privacy eq "private" 0 0 0
43 0 $self->privacy_group eq $self->page_group($page);
44 }
45  
46 0 ▶sub is_writable {
Subroutine is_writable: not called CC=3 SCAR=24.8
47 0 my $page = $self;
48 0 my $hook = pop;
49 0 ▶ return unless $hook->returned_true;
Branch: 1 branch
BranchTrueFalseTotal
unless $hook->returned_true 0 0 0
50 0 $self = $self->hub->page_privacy;
51 0 my $privacy = $self->page_privacy($page);
52 0 ▶ return 1 if $privacy eq 'public';
Branch: 1 branch
BranchTrueFalseTotal
if $privacy eq "public" 0 0 0
53 0 $self->privacy_group eq $self->page_group($page);
54 }
55  
56 0 ▶sub page_privacy_set {
Subroutine page_privacy_set: not called CC=5 SCAR=34.0
57 0 ▶ return unless $self->page_privacy_selectable;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->page_privacy_selectable 0 0 0
58 0 my $privacy = $self->cgi->privacy;
59 0 my $dir = $self->plugin_directory;
60 0 my $id = $self->pages->current->id;
61 0 my $group = $self->privacy_group;
62 0 ▶ if ($privacy eq 'public') {
Branch: 3 branches
BranchTrueFalseTotal
if ($privacy eq 'public') { } 0 0 0
elsif ($privacy eq 'protected') { } 0 0 0
elsif ($privacy eq 'private') { } 0 0 0
63 0 io->dir("$dir/$id")->rmtree;
64 }
65 elsif ($privacy eq 'protected') {
66 0 io->file("$dir/$id/group")->assert->print("$group\n");
67 0 io->file("$dir/$id/protected")->assert->touch;
68 0 io->file("$dir/$id/private")->unlink;
69 }
70 elsif ($privacy eq 'private') {
71 0 io->file("$dir/$id/group")->assert->print("$group\n");
72 0 io->file("$dir/$id/private")->assert->touch;
73 0 io->file("$dir/$id/protected")->unlink;
74 }
75 }
76  
77 0 ▶sub page_privacy_selectable {
Subroutine page_privacy_selectable: not called CC=3 SCAR=24.8
78 0 ▶ my $group = $self->privacy_group
Branch: 1 branch
BranchTrueFalseTotal
my $group = $self->privacy_group or return 0 0 0
79 or return;
80 0 ▶ my $page_group = $self->page_group
Branch: 1 branch
BranchTrueFalseTotal
my $page_group = $self->page_group or return 1 0 0 0
81 or return 1;
82 0 $group eq $page_group;
83 }
84  
85 0 ▶sub privacy_group {
Subroutine privacy_group: not called CC=1 SCAR=6.9
86 0 $self->config->privacy_group;
87 }
88  
89 0 ▶sub page_group {
Subroutine page_group: not called CC=3 SCAR=24.8
90 0 ▶ my $id = (shift || $self->pages->current)->id;
Condition0%0/3
shift() || $self->pages->current
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->pages->current
shift() $self->pages->current
Truth table0%0/3
A || B
A= shift()B= $self->pages->current
ABresult
1X1
011
000
91 0 my $dir = $self->plugin_directory;
92 0 my $group_file = "$dir/$id/group";
93 0 ▶ -f $group_file ? io($group_file)->chomp->getline : '';
Branch: 1 branch
BranchTrueFalseTotal
-f $group_file ? : 0 0 0
94 }
95  
96 0 ▶sub page_privacy {
Subroutine page_privacy: not called CC=4 SCAR=30.0
97 0 ▶ my $id = (shift || $self->pages->current)->id;
Condition0%0/3
shift() || $self->pages->current
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $self->pages->current
shift() $self->pages->current
Truth table0%0/3
A || B
A= shift()B= $self->pages->current
ABresult
1X1
011
000
98 0 my $dir = $self->plugin_directory;
99 0 ▶ -e "$dir/$id/private" ? 'private' :
Branch: 2 branches
BranchTrueFalseTotal
-e "$dir/$id/private" ? : 0 0 0
-e "$dir/$id/protected" ? : 0 0 0
100 -e "$dir/$id/protected" ? 'protected' :
101 'public';
102 }
103  
104 package Kwiki::PagePrivacy::CGI;
105 0 ▶use Kwiki::CGI -base;
Subroutine BEGIN: called CC=1 SCAR=2.6
106 cgi 'privacy';
107  
108 package Kwiki::PagePrivacy;
109  
110 __DATA__
↑ Summary