Box/Identity.pm

filter: Statementstmt 81.8% 99 / 121 Branchbran 63.2% 43 / 68 Conditioncond 53.8% 7 / 13 MC/DCmcdc 28.5% 2 / 7 Subroutinesub 84.0% 21 / 25 Podpod 90.0% 18 / 20 totaltotal 74.8% 190 / 254 CC 42 SCAR 16.0
CC
42
Cov
74%
subfolders
12.2
onlySubfolders
6.0
marked
6.0
CRAP 4.9
« Box/Tie/ARRAY.pm ↑ Summary Message/Wrapper/SpamAssassin.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::Identity;
10 3 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 $VERSION = '3.009';
12  
13 3 ▶use base qw/User::Identity::Item Mail::Reporter/;
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 # tests in tests/52message/30collect.t
21  
22  
23 0 ▶sub type { "mailbox" }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
24  
25  
26 sub new(@)
27 13 ▶{ my $class = shift;
Subroutine new: called CC=2 SCAR=7.1
Pod documented
28 13 ▶ unshift @_, 'name' if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 13 13
29 13 $class->Mail::Reporter::new(@_);
30 }
31  
32 sub init($)
33 13 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=3 SCAR=11.0
Pod undocumented
34  
35 13 $self->Mail::Reporter::init($args);
36 13 $self->User::Identity::init($args);
37  
38 13 $self->{MBI_location} = delete $args->{location};
39 13 $self->{MBI_ftype} = delete $args->{folder_type};
40 13 $self->{MBI_manager} = delete $args->{manager};
41 13 ▶ $self->{MBI_subf_type} = delete $args->{subf_type}||'Mail::Box::Collection';
Condition50%1/2
delete $args->{'subf_type'} || 'Mail::Box::Collection'
l!l
013
MC/DC0%0/1
delete $args->{'subf_type'} || 'Mail::Box::Collection'
delete $args->{'subf_type'}
Truth table50%1/2
A
A= delete $args->{'subf_type'}
Aresult
11
00
42 13 $self->{MBI_only_subs} = delete $args->{only_subs};
43 13 $self->{MBI_marked} = delete $args->{marked};
44 13 $self->{MBI_deleted} = delete $args->{deleted};
45 13 ▶ $self->{MBI_inferiors} = exists $args->{inferiors} ? $args->{inferiors} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'inferiors'} ? : 0 13 13
46  
47 13 $self;
48 }
49  
50 #-------------------------------------------
51  
52  
53 sub fullname(;$)
54 64 ▶{ my $self = shift;
Subroutine fullname: called CC=4 SCAR=13.9
Pod documented
55 64 ▶ my $delim = @_ && defined $_[0] ? shift : '/';
Branch: 1 branch
BranchTrueFalseTotal
@_ && defined $_[0] ? : 43 21 64
Condition66%2/3
@_ and defined $_[0]
!ll&&!rl&&r
21043
MC/DC50%1/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table66%2/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
56  
57 64 ▶ my $parent = $self->parent or return $self->name;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->parent or return $self->name 22 42 64
58 42 $parent->parent->fullname($delim) . $delim . $self->name;
59 }
60  
61  
62  
63 sub location(;$)
64 77 ▶{ my $self = shift;
Subroutine location: called CC=4 SCAR=14.8
Pod documented
65 77 ▶ return ($self->{MBI_location} = shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 77 77
66 77 ▶ return $self->{MBI_location} if defined $self->{MBI_location};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MBI_location"} 25 52 77
67  
68 52 my $parent = $self->parent;
69 52 ▶ unless(defined $parent)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parent) 0 52 52
70 0 { $self->log(ERROR => "Toplevel directory requires explicit location");
71 0 return undef;
72 }
73  
74 $self->folderType
75 52 ->nameOfSubFolder($self->name, $parent->parent->location)
76 }
77  
78  
79  
80 sub folderType()
81 222 ▶{ my $self = shift;
Subroutine folderType: called CC=3 SCAR=11.6
Pod documented
82 222 ▶ return $self->{MBI_ftype} if defined $self->{MBI_ftype};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MBI_ftype"} 75 147 222
83  
84 147 my $parent = $self->parent;
85 147 ▶ unless(defined $parent)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parent) 0 147 147
86 0 { $self->log(ERROR => "Toplevel directory requires explicit folder type");
87 0 return undef;
88 }
89  
90 147 $parent->parent->folderType;
91 }
92  
93  
94  
95 sub manager()
96 1 ▶{ my $self = shift;
Subroutine manager: called CC=3 SCAR=16.5
Pod documented
97 1 ▶ return $self->{MBI_manager} if $self->{MBI_manager};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBI_manager"} 1 0 1
98 0 ▶ my $parent = $self->parent or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->parent or return undef 0 0 0
99 0 $self->parent->manager;
100 }
101  
102  
103  
104 sub topfolder()
105 11 ▶{ my $self = shift;
Subroutine topfolder: called CC=2 SCAR=6.9
Pod documented
106 11 ▶ my $parent = $self->parent or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->parent or return $self 4 7 11
107 7 $parent->parent->topfolder;
108 }
109  
110  
111  
112 sub onlySubfolders(;$)
113 1 ▶{ my $self = shift;
Subroutine onlySubfolders: called CC=4 SCAR=17.9
Pod documented
114 1 ▶ return($self->{MBI_only_subs} = shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
115 1 ▶ return $self->{MBI_only_subs} if exists $self->{MBI_only_subs};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"MBI_only_subs"} 1 0 1
116 0 ▶ $self->parent ? 1 : ! $self->folderType->topFolderWithMessages;
Branch: 1 branch
BranchTrueFalseTotal
$self->parent ? : 0 0 0
117 }
118  
119  
120  
121 sub marked(;$)
122 0 ▶{ my $self = shift;
Subroutine marked: not called CC=2 SCAR=17.9
Pod documented
123 0 ▶ @_ ? ($self->{MBI_marked} = shift) : $self->{MBI_marked};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
124 }
125  
126  
127  
128 sub inferiors(;$)
129 1 ▶{ my $self = shift;
Subroutine inferiors: called CC=2 SCAR=7.2
Pod documented
130 1 ▶ @_ ? ($self->{MBI_inferiors} = shift) : $self->{MBI_inferiors};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 1 1
131 }
132  
133  
134  
135 sub deleted(;$)
136 0 ▶{ my $self = shift;
Subroutine deleted: not called CC=2 SCAR=17.9
Pod documented
137 0 ▶ @_ ? ($self->{MBI_deleted} = shift) : $self->{MBI_deleted};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
138 }
139
140 #-------------------------------------------
141  
142  
143 sub subfolders()
144 54 ▶{ my $self = shift;
Subroutine subfolders: called CC=10 SCAR=25.0
Pod documented
145 54 my $subs = $self->collection('subfolders');
146 54 ▶ return (wantarray ? $subs->roles : $subs)
Branch: 2 branches
BranchTrueFalseTotal
if defined $subs 32 22 54
wantarray ? : 3 29 32
147 if defined $subs;
148  
149 22 my @subs;
150 22 ▶ if(my $location = $self->location)
Branch: 1 branch
BranchTrueFalseTotal
if (my $location = $self->location) { } 22 0 22
151 22 { @subs = $self->folderType->listSubFolders
152 ( folder => $location
153 );
154 }
155 else
156 0 { my $mgr = $self->manager;
157 0 ▶ my $top = defined $mgr ? $mgr->folderdir : '.';
Branch: 1 branch
BranchTrueFalseTotal
defined $mgr ? : 0 0 0
158  
159 0 @subs = $self->folderType->listSubFolders
160 ( folder => $self->fullname
161 , folderdir => $top
162 );
163 }
164 22 ▶ @subs or return ();
Branch: 1 branch
BranchTrueFalseTotal
@subs or return () 18 4 22
165  
166 my $subf_type
167 4 ▶ = $self->{MBI_subf_type} || ref($self->parent) || 'Mail::Box::Collection';
Condition40%2/5
$self->{'MBI_subf_type'} || ref $self->parent || 'Mail::Box::Collection'
l!l
40
$self->{"MBI_subf_type"} or ref $self->parent
l!l&&r!l&&!r
400
MC/DC0%0/2
$self->{'MBI_subf_type'} || ref $self->parent || 'Mail::Box::Collection'
$self->{"MBI_subf_type"} ref $self->parent
Truth table33%1/3
A or B
A= $self->{"MBI_subf_type"}B= ref $self->parent
ABresult
1X1
011
000
168  
169 4 $subs = $subf_type->new('subfolders');
170  
171 4 $self->addCollection($subs);
172 4 $subs->addRole(name => $_) for @subs;
173 4 ▶ wantarray ? $subs->roles : $subs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 2 4
174 }
175  
176  
177  
178 3 ▶sub subfolderNames() { map {$_->name} shift->subfolders }
Subroutine subfolderNames: called CC=1 SCAR=0.0
Pod documented
179  
180  
181  
182 sub folder(@)
183 30 ▶{ my $self = shift;
Subroutine folder: called CC=5 SCAR=16.1
Pod documented
184 30 ▶ return $self unless @_ && defined $_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless @_ and defined $_[0] 8 22 30
Condition66%2/3
@_ and defined $_[0]
!ll&&!rl&&r
8022
MC/DC50%1/2
@_ and defined $_[0]
@_ defined $_[0]
Truth table66%2/3
A and B
A= @_B= defined $_[0]
ABresult
0X0
100
111
185  
186 22 ▶ my $subs = $self->subfolders or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $subs = $self->subfolders or return undef 1 21 22
187 21 ▶ my $nest = $subs->find(shift) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $nest = $subs->find(shift()) or return undef 2 19 21
188 19 $nest->folder(@_);
189 }
190  
191  
192  
193 sub open(@)
194 0 ▶{ my $self = shift;
Subroutine open: not called CC=1 SCAR=6.9
Pod documented
195 0 $self->manager->open($self->fullname, type => $self->folderType, @_);
196 }
197  
198  
199  
200 sub foreach($)
201 24 ▶{ my ($self, $code) = @_;
Subroutine foreach: called CC=3 SCAR=11.0
Pod documented
202 24 $code->($self);
203  
204 24 ▶ my $subs = $self->subfolders or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $subs = $self->subfolders or return () 16 8 24
205 8 $_->foreach($code) for $subs->sorted;
206 8 $self;
207 }
208  
209  
210  
211 sub addSubfolder(@)
212 1 ▶{ my $self = shift;
Subroutine addSubfolder: called CC=3 SCAR=12.6
Pod undocumented
213 1 my $subs = $self->subfolders;
214  
215 1 ▶ if(defined $subs) { ; }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $subs) { } 0 1 1
elsif (not $self->inferiors) { } 0 1 1
216 elsif(!$self->inferiors)
217 0 { my $name = $self->fullname;
218 0 $self->log(ERROR => "It is not permitted to add subfolders to $name");
219 0 return undef;
220 }
221 else
222 1 { $subs = $self->{MBI_subf_type}->new('subfolders');
223 1 $self->addCollection($subs);
224 }
225  
226 1 $subs->addRole(@_);
227 }
228  
229  
230  
231 sub remove(;$)
232 2 ▶{ my $self = shift;
Subroutine remove: called CC=4 SCAR=14.6
Pod documented
233  
234 2 my $parent = $self->parent;
235 2 ▶ unless(defined $parent)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parent) 0 2 2
236 0 { $self->log(ERROR => "The toplevel folder cannot be removed this way");
237 0 return ();
238 }
239  
240 2 ▶ return $parent->removeRole($self->name)
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 1 2
241 unless @_;
242  
243 1 my $name = shift;
244 1 ▶ my $subs = $self->subfolders or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $subs = $self->subfolders or return () 0 1 1
245 1 $subs->removeRole($name);
246 }
247  
248  
249  
250 sub rename($;$)
251 1 ▶{ my ($self, $folder, $newname) = @_;
Subroutine rename: called CC=2 SCAR=7.0
Pod documented
252 1 ▶ $newname = $self->name unless defined $newname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newname 0 1 1
253  
254 1 my $away = $self->remove;
255 1 $away->name($newname);
256  
257 1 $folder->addSubfolder($away);
258 }
259  
260 #-------------------------------------------
261  
262  
263 3 1;
264  
265  
« Box/Tie/ARRAY.pm ↑ Summary Message/Wrapper/SpamAssassin.pm »