WE/Obj.pm

filter: Statementstmt 75.7% 50 / 66 Branchbran 75.0% 18 / 24 Conditioncond 50.0% 8 / 16 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 61.1% 11 / 18 Podpod 92.8% 13 / 14 totaltotal 69.5% 103 / 148 CC 21 SCAR 17.7
CC
21
Cov
72%
object_is_insertable
20.0
is_time_restricted
8.3
use_classes
6.0
CRAP 5.9
« WebEditor/OldFeatures/SystemExplorer.pm ↑ Summary WebEditor/OldFeatures/TeaserLink.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: Obj.pm,v 1.10 2005/01/31 08:28:23 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2001 Online Office Berlin. All rights reserved.
8 # Copyright (C) 2002,2005 Slaven Rezic.
9 # This is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License, see the file COPYING.
11  
12 #
13 # Mail: slaven@rezic.de
14 # WWW: http://we-framework.sourceforge.net
15 #
16  
17 package WE::Obj;
18  
19 =head1 NAME
20  
21 WE::Obj - base object class for the web editor framework
22  
23 =head1 SYNOPSIS
24  
25 This is an abstract class.
26  
27 =head1 DESCRIPTION
28  
29 For member attributes there are accessors defined. To get the value of
30 a member named B<Id>, use:
31  
32 $object->Id;
33  
34 To set the value of a member use:
35  
36 $object->Id($new_value);
37  
38 Below is a list of member attributes which can be defined for each
39 object. The semantics apply to the L<WE::DB::Obj|WE::DB::Obj>
40 database.
41  
42 =over 4
43  
44 =item Id
45  
46 The identifier for this object. Normally, this identifier is numeric
47 (but it does not have to). The normal user should not change the Id.
48  
49 =item Title
50  
51 The title for this object. This is usually a normal string. If you
52 want to set language-dependent titles, then look at
53 L<WE::Util::LangString>.
54  
55 =item Basename
56  
57 An optional basename for this object. For backends using a
58 pathname-like scheme, this can be used to construct the basename. See
59 L<Net::FTPServer::WE_DB::Server>.
60  
61 =item Name
62  
63 An optional name for this object. This name should be unique in the
64 database and will be used for name-based queries.
65  
66 =item Keywords
67  
68 Optional keywords for this object. This is usually a normal string. If you
69 want to set language-dependent keywords, then look at
70 L<WE::Util::LangString>.
71  
72 =item TimeCreated
73  
74 The time of the creation of the object. This attribute is set
75 automatically and should not be changed. The returned value is an ISO
76 date. See L<WE::Util::Date> for conversion functions for ISO dates.
77  
78 =item TimeModified
79  
80 The time of the last modification of the object. Both attribute
81 modification and content modification are taken into account. Like in
82 C<TimeCreated>, the returned value is an ISO date.
83  
84 =item Owner
85  
86 This is the owner of the object. The owner is set automatically when
87 creating the object (see L<WE::DB/CurrentUser>). See L</NOTES> below
88 for more information.
89  
90 =item DocAuthor
91  
92 This is the original author of the object. This should be set only if
93 the original author differs from the technical Owner of the object.
94  
95 =item Rights
96  
97 For now, the value for the B<Rights> member is a freely definable. Its
98 value is not used nor it is inherited to other objects.
99  
100 =item TimeOpen
101  
102 This member can be set to an ISO date to indicate the start of
103 publication for the object.
104  
105 =item TimeExpire
106  
107 This member can be set to an ISO date to indicate the end of
108 publication for the object.
109  
110 =item Version_Owner
111  
112 This member is only set for versions and for checked out objects. It
113 holds the user who made this version. This member is set
114 automatically.
115  
116 =item Version_Time
117  
118 This member is only set for versions and for checked out objects. It
119 holds the time when this version is made. This member is set
120 automatically.
121  
122 =item Version_Comment
123  
124 This member is only set for versions and for checked out objects. It
125 holds the (optional) log message (or comment) for this version.
126  
127 =item Version_Number
128  
129 This member is only set for versions and for checked out objects. It
130 holds the version number for this version. Normally version numbers
131 begin at "1.0" and are incremented by 0.1 (that is, the next would be
132 "1.1", "1.2" and so on), but version numbers are not necessarily
133 numbers.
134  
135 =item Version_Parent
136  
137 This member is only set for versions and for checked out objects. It
138 holds the Id of the original object belonging to this version.
139  
140 =item Release_State
141  
142 The following values are possible:
143  
144 =over
145  
146 =item released
147  
148 The object is released.
149  
150 =item inactive
151  
152 The object should never be released.
153  
154 =item modified
155  
156 The object was modified since the last release or it was never
157 released.
158  
159 =back
160  
161 =item Release_*
162  
163 The attributes Release_Author, Release_Flow, Release_Publishers,
164 Release_ReviewedBy, and Release_TargetFolder are
165 defined, but there is not functionality for these.
166  
167 =item LockedBy
168  
169 Holds the user who is locking this object.
170  
171 =item LockType
172  
173 The LockType may be B<PermanentLock> or B<SessionLock>. A permanent
174 lock is valid over sessions. A session lock is only valid for the
175 session of the locking user. If the locking user logs out (or the
176 system can determine by some other means that the user is not logged
177 in --- see L<WE::DB::OnlineUser>), then the lock is not valid anymore.
178  
179 =item Dirty
180  
181 Indicates that the object is changed after the last check in. This is
182 the combination of B<DirtyAttributes> and B<DirtyContent>.
183  
184 =item DirtyAttributes
185  
186 Indicates that the attributes of the object changed after the last
187 check in.
188  
189 =item DirtyContent
190  
191 Indicates that the content of the object changed after the last check
192 in.
193  
194 =back
195  
196 Other custom attributes may be set by accessing the object as a hash:
197  
198 $object->{My_Attribute} = ["my value1", "my value2"];
199  
200 As you can see, the value may also be a complex perl data structure.
201 It is a good idea to use a prefix (like "My_" in the sample above) to
202 minimize the chance of name clashes.
203  
204 For other standard attributes, look at the documentation of the sub
205 classes of WE::Obj.
206  
207 =head2 METHODS
208  
209 =over 4
210  
211 =cut
212  
213 17 ▶use base qw(Class::Accessor);
Subroutine BEGIN: called CC=1 SCAR=0.0
214 17 __PACKAGE__->mk_accessors
215 (qw(Id Title Basename Name Keywords
216 TimeCreated TimeModified Owner DocAuthor Rights TimeOpen TimeExpire
217 Version_Owner Version_Time Version_Comment Version_Number
218 Version_Parent
219 Release_Author Release_Flow Release_Publishers Release_ReviewedBy
220 Release_State Release_TargetFolder
221 LockedBy LockType LockTime
222 Dirty DirtyAttributes DirtyContent));
223  
224 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
225 17 ▶use vars qw($VERSION @all_classes);
Subroutine BEGIN: called CC=1 SCAR=0.0
226 17 $VERSION = sprintf("%d.%02d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/);
227  
228 17 @all_classes = qw(Sites Site Folder LangCluster Sequence Doc LangDoc);
229  
230 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
231 1 my($class, %args) = @_;
232 1 my $self = {%args};
233 1 bless $self, $class;
234 }
235  
236 =item instantiable
237  
238 Return true if the object is instantiable (e.g. only folders and
239 documents).
240  
241 =cut
242  
243 0 ▶sub instantiable { 0 }
Subroutine instantiable: not called CC=1 SCAR=6.9
Pod documented
244  
245 =item insertable_types
246  
247 Return an array reference of class names which are insertable into
248 this object. Applies only for folder-like objects.
249  
250 =cut
251  
252 0 ▶sub insertable_types { [] }
Subroutine insertable_types: not called CC=1 SCAR=6.9
Pod documented
253  
254 =item use_classes(@classes)
255  
256 Load into perl all given classes. C<:all> means: load all known
257 classes.
258  
259 =cut
260  
261 14 ▶sub use_classes {
Subroutine use_classes: called CC=6 SCAR=18.0
Pod documented
262 14 my($self, @classes) = @_;
263 14 foreach my $class (@classes) {
264 # allow abbreviations
265 112 ▶ if ($class !~ /^WE::Obj/ && $class !~ /^:/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($class =~ /^WE::Obj/ or $class =~ /^:/) 98 14 112
Condition66%2/3
$class =~ /^WE::Obj/ or $class =~ /^:/
l!l&&r!l&&!r
01498
MC/DC50%1/2
$class =~ /^WE::Obj/ or $class =~ /^:/
$class =~ /^WE::Obj/ $class =~ /^:/
Truth table66%2/3
A or B
A= $class =~ /^WE::Obj/B= $class =~ /^:/
ABresult
1X1
011
000
266 98 $class = "WE::Obj::$class";
267 }
268 112 ▶ if ($class eq ':all') {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq ":all") 14 98 112
269 14 push @classes, @all_classes;
270 14 next;
271 }
272 98 eval "require $class; $class->import";
273 98 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 98 98
274 }
275 }
276  
277 =item object_is_insertable($obj)
278  
279 Return true if the given object is insertable.
280  
281 =cut
282  
283 0 ▶sub object_is_insertable {
Subroutine object_is_insertable: not called CC=4 SCAR=30.0
Pod documented
284 0 my($self, $obj) = @_;
285 0 foreach (@{$self->insertable_types}) {
286 0 ▶ return 1 if $obj->isa($_) || $_ eq ':all';
Branch: 1 branch
BranchTrueFalseTotal
if $obj->isa($_) or $_ eq ":all" 0 0 0
Condition0%0/3
$obj->isa($_) or $_ eq ":all"
l!l&&r!l&&!r
000
MC/DC0%0/2
$obj->isa($_) or $_ eq ":all"
$obj->isa($_) $_ eq ":all"
Truth table0%0/3
A or B
A= $obj->isa($_)B= $_ eq ":all"
ABresult
1X1
011
000
287 }
288 0 0;
289 }
290  
291 =item clone
292  
293 Clone the given object.
294  
295 =cut
296  
297 1 ▶sub clone {
Subroutine clone: called CC=3 SCAR=13.0
Pod documented
298 1 my($self) = @_;
299 1 ▶ if (eval { local $SIG{__DIE__}; require Storable; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { local $SIG{'__DIE__'}; require Storable; 1 } }) { } 1 0 1
300 1 local $Storable::forgive_me = 1;
301 1 Storable::dclone($self);
302 } else {
303 17 ▶ no strict 'vars'; # ignore $obj_copy
Subroutine BEGIN: called CC=1 SCAR=0.0
304 0 require Data::Dumper;
305 0 my $dd = new Data::Dumper([$self],['obj_copy']);
306 0 my $cloned = eval $dd->Dump;
307 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
308 0 $cloned;
309 }
310 }
311  
312 =item is_doc, is_folder, is_site
313  
314 Return true if the object is a document, folder or site.
315  
316 =cut
317  
318 0 ▶sub is_doc { $_[0]->isa('WE::Obj::DocObj') }
Subroutine is_doc: not called CC=1 SCAR=6.9
Pod documented
319 0 ▶sub is_folder { $_[0]->isa('WE::Obj::FolderObj') }
Subroutine is_folder: not called CC=1 SCAR=6.9
Pod documented
320 0 ▶sub is_site { $_[0]->isa('WE::Obj::Site') }
Subroutine is_site: not called CC=1 SCAR=6.9
Pod documented
321  
322 =item is_sequence
323  
324 Return true if the object is a sequence. Remember that a Sequence is
325 always a FolderObj, so the return value of C<is_folder> will also be
326 true.
327  
328 =cut
329  
330 0 ▶sub is_sequence { $_[0]->isa('WE::Obj::Sequence') }
Subroutine is_sequence: not called CC=1 SCAR=6.9
Pod documented
331  
332 =item field_is_date($fieldname)
333  
334 Return true if the given field should be treated as a date/time field.
335  
336 =cut
337  
338 4 ▶sub field_is_date {
Subroutine field_is_date: called CC=2 SCAR=6.9
Pod documented
339 4 my($self, $field) = @_;
340 4 ▶ $field =~ /^(TimeCreated|TimeModified|TimeOpen|TimeExpire|Version_Time|LockTime)$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$field =~ /^(TimeCreated|TimeModified|TimeOpen|TimeExpire|Version_Time|LockTime)$/ ? : 3 1 4
341 }
342  
343 =item field_is_user($fieldname)
344  
345 Return true if the given field should be treated as a username field.
346  
347 =cut
348  
349 2 ▶sub field_is_user {
Subroutine field_is_user: called CC=2 SCAR=6.9
Pod documented
350 2 my($self, $field) = @_;
351 2 ▶ $field =~ /^(Owner|Version_Owner|Release_Author|Release_ReviewedBy|LockedBy)$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$field =~ /^(Owner|Version_Owner|Release_Author|Release_ReviewedBy|LockedBy)$/ ? : 1 1 2
352 }
353  
354 =item field_is_user($fieldname)
355  
356 Return true if the given field should not be edited (e.g. Id field).
357  
358 =cut
359  
360 2 ▶sub field_is_not_editable {
Subroutine field_is_not_editable: called CC=2 SCAR=6.9
Pod undocumented
361 2 my($self, $field) = @_;
362 2 ▶ $field =~ /^(Id)$/ ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$field =~ /^(Id)$/ ? : 1 1 2
363 }
364  
365 =item is_time_restricted($now)
366  
367 Return true if the object is restricted via C<TimeOpen> and
368 C<TimeExpire>. To adjust the current time, set C<$now> to a unix epoch
369 time in seconds.
370  
371 =cut
372  
373 3 ▶sub is_time_restricted {
Subroutine is_time_restricted: called CC=8 SCAR=21.1
Pod documented
374 3 my($self, $now) = @_;
375 3 ▶ if (!defined $now) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $now) 1 2 3
376 1 require WE::Util::Date;
377 1 $now = WE::Util::Date::epoch2isodate(time);
378 }
379  
380 3 ▶ my $timeopen = $self->TimeOpen || undef;
Condition50%1/2
$self->TimeOpen || undef
l!l
30
MC/DC0%0/1
$self->TimeOpen || undef
$self->TimeOpen
Truth table50%1/2
A
A= $self->TimeOpen
Aresult
11
00
381 3 ▶ return 1 if (defined $timeopen && $timeopen gt $now);
Branch: 1 branch
BranchTrueFalseTotal
if defined $timeopen and $timeopen gt $now 1 2 3
Condition66%2/3
defined $timeopen and $timeopen gt $now
!ll&&!rl&&r
021
MC/DC50%1/2
defined $timeopen and $timeopen gt $now
defined $timeopen $timeopen gt $now
Truth table66%2/3
A and B
A= defined $timeopenB= $timeopen gt $now
ABresult
0X0
100
111
382 2 ▶ my $timeexpire = $self->TimeExpire || undef;
Condition50%1/2
$self->TimeExpire || undef
l!l
20
MC/DC0%0/1
$self->TimeExpire || undef
$self->TimeExpire
Truth table50%1/2
A
A= $self->TimeExpire
Aresult
11
00
383 2 ▶ return 1 if (defined $timeexpire && $timeexpire lt $now);
Branch: 1 branch
BranchTrueFalseTotal
if defined $timeexpire and $timeexpire lt $now 1 1 2
Condition66%2/3
defined $timeexpire and $timeexpire lt $now
!ll&&!rl&&r
011
MC/DC50%1/2
defined $timeexpire and $timeexpire lt $now
defined $timeexpire $timeexpire lt $now
Truth table66%2/3
A and B
A= defined $timeexpireB= $timeexpire lt $now
ABresult
0X0
100
111
384 1 0;
385 }
386  
387 17 1;
388  
389 __END__
« WebEditor/OldFeatures/SystemExplorer.pm ↑ Summary WebEditor/OldFeatures/TeaserLink.pm »