Box/Manage/User.pm

filter: Statementstmt 35.8% 33 / 92 Branchbran 8.7% 4 / 46 Conditioncond 27.2% 3 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 57.1% 8 / 14 Podpod 88.8% 8 / 9 totaltotal 31.4% 56 / 178 CC 29 SCAR 38.0
CC
29
Cov
27%
create
132.0
rename
42.0
folder
12.0
CRAP 44.7
« Box/Message.pm ↑ Summary Box/Dir.pm »
1 # Copyrights 2001-2020 by [Mark Overmeer].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution Mail-Box. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Box::Manage::User;
10 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 $VERSION = '3.009';
12  
13 3 ▶use base 'Mail::Box::Manager';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use Mail::Box::Collection ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 #-------------------------------------------
21  
22  
23 sub init($)
24 2 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=8 SCAR=22.0
Pod undocumented
25  
26 2 ▶ $self->SUPER::init($args) or return ();
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init($args) or return () 0 2 2
27  
28 2 my $identity = $self->{MBMU_id} = $args->{identity};
29 2 ▶ defined $identity or die;
Branch: 1 branch
BranchTrueFalseTotal
defined $identity or die 0 2 2
30  
31 2 ▶ my $top = $args->{folder_id_type} || 'Mail::Box::Identity';
Condition50%1/2
$args->{'folder_id_type'} || 'Mail::Box::Identity'
l!l
02
MC/DC0%0/1
$args->{'folder_id_type'} || 'Mail::Box::Identity'
$args->{'folder_id_type'}
Truth table50%1/2
A
A= $args->{'folder_id_type'}
Aresult
11
00
32 2 ▶ my $coltype = $args->{collection_type} || 'Mail::Box::Collection';
Condition50%1/2
$args->{'collection_type'} || 'Mail::Box::Collection'
l!l
02
MC/DC0%0/1
$args->{'collection_type'} || 'Mail::Box::Collection'
$args->{'collection_type'}
Truth table50%1/2
A
A= $args->{'collection_type'}
Aresult
11
00
33  
34 2 ▶ unless(ref $top)
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $top) 2 0 2
35 2 { my $name = $args->{topfolder_name};
36 2 ▶ $name = '=' unless defined $name; # MailBox's abbrev to top
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 2 0 2
37  
38 2 $top = $top->new
39 ( name => $name
40 , manager => $self
41 , location => scalar($self->folderdir)
42 , folder_type => $self->defaultFolderType
43 , collection_type => $coltype
44 );
45 }
46  
47 2 $self->{MBMU_topfolder} = $top;
48 2 ▶ $self->{MBMU_delim} = $args->{delimiter} || '/';
Condition50%1/2
$args->{'delimiter'} || '/'
l!l
02
MC/DC0%0/1
$args->{'delimiter'} || '/'
$args->{'delimiter'}
Truth table50%1/2
A
A= $args->{'delimiter'}
Aresult
11
00
49 2 $self->{MBMU_inbox} = $args->{inbox};
50  
51 2 $self;
52 }
53  
54 #-------------------------------------------
55  
56  
57 1 ▶sub identity() { shift->{MBMU_id} }
Subroutine identity: called CC=1 SCAR=0.0
Pod documented
58  
59 #-------------------------------------------
60  
61  
62 sub inbox(;$)
63 0 ▶{ my $self = shift;
Subroutine inbox: not called CC=2 SCAR=17.9
Pod documented
64 0 ▶ @_ ? ($self->{MBMU_inbox} = shift) : $self->{MBMU_inbox};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
65 }
66  
67 #-------------------------------------------
68  
69  
70 # A lot of work still has to be done here: all moves etc must inform
71 # the "existence" administration as well.
72  
73 #-------------------------------------------
74  
75  
76 2 ▶sub topfolder() { shift->{MBMU_topfolder} }
Subroutine topfolder: called CC=1 SCAR=0.0
Pod documented
77  
78  
79  
80 sub folder($)
81 0 ▶{ my ($self, $name) = @_;
Subroutine folder: not called CC=3 SCAR=24.8
Pod documented
82 0 ▶ my $top = $self->topfolder or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $top = $self->topfolder or return () 0 0 0
83 0 my @path = split $self->{MBMU_delim}, $name;
84 0 ▶ return () unless shift @path eq $top->name;
Branch: 1 branch
BranchTrueFalseTotal
unless shift @path eq $top->name 0 0 0
85  
86 0 $top->folder(@path);
87 }
88  
89  
90  
91 sub folderCollection($)
92 0 ▶{ my ($self, $name) = @_;
Subroutine folderCollection: not called CC=3 SCAR=24.8
Pod documented
93 0 ▶ my $top = $self->topfolder or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $top = $self->topfolder or return () 0 0 0
94  
95 0 my @path = split $self->{MBMU_delim}, $name;
96 0 ▶ unless(shift @path eq $top->name)
Branch: 1 branch
BranchTrueFalseTotal
unless (shift @path eq $top->name) 0 0 0
97 0 { $self->log(ERROR => "Folder name $name not under top.");
98 0 return ();
99 }
100  
101 0 my $base = pop @path;
102  
103 0 ($top->folder(@path), $base);
104 }
105  
106  
107  
108 # This feature is thoroughly tested in the Mail::Box::Netzwert distribution
109  
110 sub create($@)
111 0 ▶{ my ($self, $name, %args) = @_;
Subroutine create: not called CC=11 SCAR=48.8
Pod documented
112 0 my ($dir, $base) = $self->folderCollection($name);
113  
114 0 ▶ unless(defined $dir)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $dir) 0 0 0
115 0 ▶ { unless($args{create_supers})
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"create_supers"}) 0 0 0
116 0 { $self->log(ERROR => "Cannot create $name: higher levels missing");
117 0 return undef;
118 }
119  
120 0 ▶ (my $upper = $name) =~ s!$self->{MBMU_delim}$base!!
Branch: 1 branch
BranchTrueFalseTotal
(my $upper = $name) =~ s/$self->{"MBMU_delim"}$base// or die "$name - $base" 0 0 0
121 or die "$name - $base";
122  
123 0 $dir = $self->create($upper, %args, deleted => 1);
124 }
125  
126 0 my $id = $dir->folder($base);
127 0 ▶ if(!defined $id)
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $id) { } 0 0 0
elsif ($args{'deleted'}) { } 0 0 0
elsif ($id->deleted) { } 0 0 0
128 0 ▶ { my $idopt= $args{id_options} || [];
Condition0%0/2
$args{'id_options'} || []
l!l
00
MC/DC0%0/1
$args{'id_options'} || []
$args{'id_options'}
Truth table0%0/2
A
A= $args{'id_options'}
Aresult
11
00
129 0 $id = $dir->addSubfolder($base, @$idopt, deleted => $args{deleted});
130 }
131 elsif($args{deleted})
132 0 { $id->deleted(1);
133 0 return $id;
134 }
135 elsif($id->deleted)
136 { # Revive! Raise the death!
137 0 $id->deleted(0);
138 }
139 else
140 { # Bumped into existing folder
141 0 $self->log(ERROR => "Folder $name already exists");
142 0 return undef;
143 }
144  
145 0 ▶ if(!defined $args{create_real} || $args{create_real})
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $args{"create_real"} or $args{"create_real"}) 0 0 0
Condition0%0/3
not defined $args{"create_real"} or $args{"create_real"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $args{"create_real"} or $args{"create_real"}
not defined $args{"create_real"} $args{"create_real"}
Truth table0%0/3
not(A) or B
A= not defined $args{"create_real"}B= $args{"create_real"}
ABresult
1X1
011
000
146 0 ▶ { $self->defaultFolderType->create($id->location, %args)
Branch: 1 branch
BranchTrueFalseTotal
$self->defaultFolderType->create($id->location, %args) or return undef 0 0 0
147 or return undef;
148 }
149  
150 0 $id;
151 }
152  
153
154  
155 sub delete($)
156 0 ▶{ my ($self, $name) = @_;
Subroutine delete: not called CC=2 SCAR=17.9
Pod documented
157 0 ▶ my $id = $self->folder($name) or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $id = $self->folder($name) or return () 0 0 0
158 0 $id->remove;
159  
160 0 $self->SUPER::delete($name);
161 }
162  
163  
164  
165 sub rename($$@)
166 0 ▶{ my ($self, $oldname, $newname, %args) = @_;
Subroutine rename: not called CC=6 SCAR=37.4
Pod documented
167  
168 0 my $old = $self->folder($oldname);
169 0 ▶ unless(defined $old)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $old) 0 0 0
170 0 { $self->log(WARNING
171 => "Source for rename does not exist: $oldname to $newname");
172 0 return ();
173 }
174  
175 0 my ($newdir, $base) = $self->folderCollection($newname);
176 0 ▶ unless(defined $newdir)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $newdir) 0 0 0
177 0 ▶ { unless($args{create_supers})
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"create_supers"}) 0 0 0
178 0 { $self->log(ERROR
179 => "Cannot rename $oldname to $newname: higher levels missing");
180 0 return ();
181 }
182  
183 0 ▶ (my $upper = $newname) =~ s!$self->{MBMU_delim}$base!!
Branch: 1 branch
BranchTrueFalseTotal
(my $upper = $newname) =~ s/$self->{"MBMU_delim"}$base// or die "$newname - $base" 0 0 0
184 or die "$newname - $base";
185  
186 0 $newdir = $self->create($upper, %args, deleted => 1);
187 }
188  
189 0 my $oldlocation = $old->location;
190 0 my $new = $old->rename($newdir, $base);
191  
192 0 my $newlocation = $new->location;
193 0 ▶ if($oldlocation ne $newlocation)
Branch: 1 branch
BranchTrueFalseTotal
if ($oldlocation ne $newlocation) 0 0 0
194 0 { require Carp;
195 0 croak("Physical folder relocation not yet implemented");
196 # this needs a $old->rename(xx,yy) which isn't implemented yet
197 }
198  
199 0 $self->log(PROGRESS => "Renamed folder $oldname to $newname");
200 0 $new;
201 }
202  
203 #-------------------------------------------
204  
205  
206 3 1;
« Box/Message.pm ↑ Summary Box/Dir.pm »