Box/Identity.pm

filter: Statementstmt 85.7% 96 / 112 Branchbran 63.6% 42 / 66 Conditioncond 50.0% 8 / 16 MC/DCmcdc 22.2% 2 / 9 Subroutinesub 84.0% 21 / 25 Podpod 90.0% 18 / 20 totaltotal 75.4% 187 / 248 CC 42 SCAR 15.9
CC
42
Cov
75%
subfolders
12.2
onlySubfolders
6.0
marked
6.0
CRAP 4.9
« Box/Locker/Multi.pm ↑ Summary Box/Locker.pm »
1 # This code is part of Perl distribution Mail-Box version 4.02.
2 # The POD got stripped from this file by OODoc version 3.06.
3 # For contributors see file ChangeLog.
4  
5 # This software is copyright (c) 2001-2026 by Mark Overmeer.
6  
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10  
11  
12 package Mail::Box::Identity;{
13 3 our $VERSION = '4.02';
14 }
15  
16 3 ▶use parent qw/User::Identity::Item Mail::Reporter/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 3 ▶use Log::Report 'mail-box', import => [ qw/__x error/ ];
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 ▶use Mail::Box::Collection ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # tests in tests/52message/30collect.t
26  
27 #--------------------
28  
29 sub new(@)
30 13 ▶{ my $class = shift;
Subroutine new: called CC=2 SCAR=7.1
Pod documented
31 13 ▶ unshift @_, 'name' if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 0 13 13
32 13 $class->Mail::Reporter::new(@_);
33 }
34  
35 sub init($)
36 13 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=3 SCAR=11.0
Pod undocumented
37  
38 13 $self->Mail::Reporter::init($args);
39 13 $self->User::Identity::init($args);
40  
41 13 $self->{MBI_location} = delete $args->{location};
42 13 $self->{MBI_ftype} = delete $args->{folder_type};
43 13 $self->{MBI_manager} = delete $args->{manager};
44 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
45 13 $self->{MBI_only_subs} = delete $args->{only_subs};
46 13 $self->{MBI_marked} = delete $args->{marked};
47 13 $self->{MBI_deleted} = delete $args->{deleted};
48 13 ▶ $self->{MBI_inferiors} = exists $args->{inferiors} ? $args->{inferiors} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'inferiors'} ? : 0 13 13
49  
50 13 $self;
51 }
52  
53 #--------------------
54  
55 0 ▶sub type { "mailbox" }
Subroutine type: not called CC=1 SCAR=6.9
Pod documented
56  
57  
58 sub fullname(;$)
59 64 ▶{ my $self = shift;
Subroutine fullname: called CC=4 SCAR=13.9
Pod documented
60 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
61  
62 64 ▶ my $parent = $self->parent or return $self->name;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->parent or return $self->name 42 22 64
63 42 $parent->parent->fullname($delim) . $delim . $self->name;
64 }
65  
66  
67 sub location(;$)
68 77 ▶{ my $self = shift;
Subroutine location: called CC=4 SCAR=14.1
Pod documented
69 77 ▶ return ($self->{MBI_location} = shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 77 77
70 77 ▶ return $self->{MBI_location} if defined $self->{MBI_location};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"MBI_location"} 25 52 77
71  
72 52 ▶ my $parent = $self->parent
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->parent or &error(&__x("toplevel directory requires explicit location.")) 52 0 52
73 or error __x"toplevel directory requires explicit location.";
74  
75 52 $self->folderType->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.0
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
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->parent or &error(&__x("toplevel directory requires explicit folder type.")) 147 0 147
85 or error __x"toplevel directory requires explicit folder type.";
86  
87 147 $parent->parent->folderType;
88 }
89  
90  
91  
92 sub manager()
93 1 ▶{ my $self = shift;
Subroutine manager: called CC=3 SCAR=16.5
Pod documented
94 1 ▶ return $self->{MBI_manager} if $self->{MBI_manager};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"MBI_manager"} 1 0 1
95 0 ▶ my $parent = $self->parent or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->parent or return undef 0 0 0
96 0 $self->parent->manager;
97 }
98  
99  
100  
101 sub topfolder()
102 11 ▶{ my $self = shift;
Subroutine topfolder: called CC=2 SCAR=6.9
Pod documented
103 11 ▶ my $parent = $self->parent or return $self;
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->parent or return $self 7 4 11
104 7 $parent->parent->topfolder;
105 }
106  
107  
108  
109 sub onlySubfolders(;$)
110 1 ▶{ my $self = shift;
Subroutine onlySubfolders: called CC=4 SCAR=17.9
Pod documented
111 1 ▶ return($self->{MBI_only_subs} = shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
112 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
113 0 ▶ $self->parent ? 1 : ! $self->folderType->topFolderWithMessages;
Branch: 1 branch
BranchTrueFalseTotal
$self->parent ? : 0 0 0
114 }
115  
116  
117  
118 sub marked(;$)
119 0 ▶{ my $self = shift;
Subroutine marked: not called CC=2 SCAR=17.9
Pod documented
120 0 ▶ @_ ? ($self->{MBI_marked} = shift) : $self->{MBI_marked};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
121 }
122  
123  
124  
125 sub inferiors(;$)
126 1 ▶{ my $self = shift;
Subroutine inferiors: called CC=2 SCAR=7.2
Pod documented
127 1 ▶ @_ ? ($self->{MBI_inferiors} = shift) : $self->{MBI_inferiors};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 1 1
128 }
129  
130  
131  
132 sub deleted(;$)
133 0 ▶{ my $self = shift;
Subroutine deleted: not called CC=2 SCAR=17.9
Pod documented
134 0 ▶ @_ ? ($self->{MBI_deleted} = shift) : $self->{MBI_deleted};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
135 }
136  
137 #--------------------
138  
139 sub subfolders()
140 54 ▶{ my $self = shift;
Subroutine subfolders: called CC=10 SCAR=25.0
Pod documented
141 54 my $subs = $self->collection('subfolders');
142 54 ▶ return (wantarray ? $subs->roles : $subs)
Branch: 2 branches
BranchTrueFalseTotal
if defined $subs 32 22 54
wantarray ? : 3 29 32
143 if defined $subs;
144  
145 22 my @subs;
146 22 ▶ if(my $location = $self->location)
Branch: 1 branch
BranchTrueFalseTotal
if (my $location = $self->location) { } 22 0 22
147 22 { @subs = $self->folderType->listSubFolders(folder => $location);
148 }
149 else
150 0 { my $mgr = $self->manager;
151 0 ▶ my $top = defined $mgr ? $mgr->folderdir : '.';
Branch: 1 branch
BranchTrueFalseTotal
defined $mgr ? : 0 0 0
152 0 @subs = $self->folderType->listSubFolders(folder => $self->fullname, folderdir => $top);
153 }
154 22 ▶ @subs or return ();
Branch: 1 branch
BranchTrueFalseTotal
@subs or return () 4 18 22
155  
156 4 ▶ my $subf_type = $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
157  
158 4 $subs = $subf_type->new('subfolders');
159  
160 4 $self->addCollection($subs);
161 4 $subs->addRole(name => $_) for @subs;
162 4 ▶ wantarray ? $subs->roles : $subs;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 2 4
163 }
164  
165  
166  
167 3 ▶sub subfolderNames() { map $_->name, $_[0]->subfolders }
Subroutine subfolderNames: called CC=1 SCAR=0.0
Pod documented
168  
169  
170  
171 sub folder(@)
172 30 ▶{ my $self = shift;
Subroutine folder: called CC=5 SCAR=16.1
Pod documented
173 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
174  
175 22 ▶ my $subs = $self->subfolders or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $subs = $self->subfolders or return undef 21 1 22
176 21 ▶ my $nest = $subs->find(shift) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $nest = $subs->find(shift()) or return undef 19 2 21
177 19 $nest->folder(@_);
178 }
179  
180  
181 sub open(@)
182 0 ▶{ my $self = shift;
Subroutine open: not called CC=1 SCAR=6.9
Pod documented
183 0 $self->manager->open($self->fullname, type => $self->folderType, @_);
184 }
185  
186  
187 sub foreach($)
188 24 ▶{ my ($self, $code) = @_;
Subroutine foreach: called CC=3 SCAR=11.0
Pod documented
189 24 $code->($self);
190  
191 24 ▶ my $subs = $self->subfolders or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $subs = $self->subfolders or return () 8 16 24
192 8 $_->foreach($code) for $subs->sorted;
193 8 $self;
194 }
195  
196  
197  
198 sub addSubfolder(@)
199 1 ▶{ my $self = shift;
Subroutine addSubfolder: called CC=3 SCAR=12.6
Pod undocumented
200 1 my $subs = $self->subfolders;
201  
202 1 ▶ if(defined $subs) { ; }
Branch: 2 branches
BranchTrueFalseTotal
if (defined $subs) { } 0 1 1
elsif (not $self->inferiors) { } 0 1 1
203 elsif(!$self->inferiors)
204 0 { my $name = $self->fullname;
205 0 error __x"it is not permitted to add subfolders to {folder}.", folder => $name;
206 0 return undef;
207 }
208 else
209 1 { $subs = $self->{MBI_subf_type}->new('subfolders');
210 1 $self->addCollection($subs);
211 }
212  
213 1 $subs->addRole(@_);
214 }
215  
216  
217  
218 sub remove(;$)
219 2 ▶{ my $self = shift;
Subroutine remove: called CC=4 SCAR=14.0
Pod documented
220  
221 2 ▶ my $parent = $self->parent
Branch: 1 branch
BranchTrueFalseTotal
my $parent = $self->parent or &error(&__x("the toplevel folder cannot be removed this way.")) 2 0 2
222 or error __x"the toplevel folder cannot be removed this way.";
223  
224 2 ▶ @_ or return $parent->removeRole($self->name);
Branch: 1 branch
BranchTrueFalseTotal
@_ or return $parent->removeRole($self->name) 1 1 2
225  
226 1 my $name = shift;
227 1 ▶ my $subs = $self->subfolders or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $subs = $self->subfolders or return () 1 0 1
228 1 $subs->removeRole($name);
229 }
230  
231  
232 sub rename($;$)
233 1 ▶{ my ($self, $folder, $newname) = @_;
Subroutine rename: called CC=2 SCAR=7.2
Pod documented
234 1 ▶ $newname //= $self->name;
Condition33%1/3
$newname //= $self->name
l!l&&r!l&&!r
100
MC/DC0%0/2
$newname //= $self->name
$newname $self->name
Truth table33%1/3
A //= B
A= $newnameB= $self->name
ABresult
1X1
011
000
235 1 my $away = $self->remove;
236 1 $away->name($newname);
237  
238 1 $folder->addSubfolder($away);
239 }
240  
241 3 1;
« Box/Locker/Multi.pm ↑ Summary Box/Locker.pm »