WE/DB/FS.pm

filter: Statementstmt 6.9% 38 / 544 Branchbran 0.0% 0 / 252 Conditioncond 0.0% 0 / 14 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 18.9% 11 / 58 Podpod 10.7% 3 / 28 totaltotal 5.7% 52 / 905 CC 137 SCAR 43.9
CC
137
Cov
5%
ci
380.0
children_ids
110.0
insert_doc
110.0
CRAP 80.6
« WE/Util/Functions.pm ↑ Summary WebEditor/SystemExplorer.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: FS.pm,v 1.6 2003/01/19 14:31:08 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2002 Slaven Rezic. All rights reserved.
8 # This package is free software; you can redistribute it and/or
9 # modify it under the same terms as Perl itself.
10 #
11 # Mail: slaven@rezic.de
12 # WWW: http://www.rezic.de/eserte/
13 #
14  
15 package WE::DB::FS;
16 1 ▶use base qw(WE::DB::ObjBase);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 $VERSION = sprintf("%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/);
21  
22 1 __PACKAGE__->mk_accessors(qw(MetaPrefix MetaSuffix RootDirectory
23 Except ExceptPat VCS
24 LockFile
25 ));
26  
27 1 ▶use Fcntl ':flock';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use File::Spec::Functions qw(:ALL);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use File::Copy (); # move and copy are also WE::DB::FS methods
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use YAML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use WE::Util::MIME;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use WE::Util::Date;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
36 0 my($class, $root, $rootdirectory, %args) = @_;
37 0 my $self = {};
38 0 bless $self, $class;
39  
40 0 ▶ $args{-locking} = 0 unless defined $args{-locking};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"-locking"} 0 0 0
41 0 ▶ $args{-connect} = 1 unless defined $args{-connect};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $args{"-connect"} 0 0 0
42  
43 0 $self->MetaPrefix(".meta.");
44 0 $self->MetaSuffix("");
45 0 $self->RootDirectory($rootdirectory);
46 0 $self->VCS("RCS");
47 0 $self->LockFile(".lock");
48  
49 0 $self->Root($root);
50 0 $self->Connected(0);
51  
52 0 ▶ if ($args{-connect}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"-connect"}) 0 0 0
53 0 $self->connect;
54 }
55  
56 0 $self;
57 }
58  
59 0 ▶sub connect {
Subroutine connect: not called CC=1 SCAR=6.9
Pod undocumented
60 0 my $self = shift;
61 0 $self->_lock;
62 0 $self->Connected(1);
63 }
64  
65 0 ▶sub connect_if_necessary {
Subroutine connect_if_necessary: not called CC=4 SCAR=30.0
Pod documented
66 0 my($self, $sub) = @_;
67 0 my $connected = $self->Connected;
68 0 my $do_disconnect;
69 0 ▶ if (!$connected) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($connected) 0 0 0
70 0 $self->connect;
71 0 $do_disconnect=1;
72 }
73 # XXX use wantarray!
74 0 my $r;
75 0 eval {
76 0 ($r) = $sub->();
77 };
78 0 my $err = $@;
79 0 ▶ if ($do_disconnect) {
Branch: 1 branch
BranchTrueFalseTotal
if ($do_disconnect) 0 0 0
80 0 $self->disconnect;
81 }
82 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
83 0 die $err;
84 }
85 0 $r;
86 }
87  
88 0 ▶sub disconnect {
Subroutine disconnect: not called CC=2 SCAR=17.9
Pod documented
89 0 my $self = shift;
90 0 ▶ if ($self->Connected) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Connected) 0 0 0
91 0 $self->_unlock;
92 0 $self->Connected(0);
93 }
94 }
95  
96 0 ▶sub _lock {
Subroutine _lock: not called CC=2 SCAR=17.9
97 0 my $self = shift;
98 0 my $lockfile = catfile($self->RootDirectory, $self->LockFile);
99 0 ▶ open(LOCK, ">$lockfile") or die "Can't write to $lockfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
open LOCK, ">$lockfile" or die "Can't write to ${lockfile}: $!" 0 0 0
100 0 flock(LOCK, LOCK_EX);
101 }
102  
103 0 ▶sub _unlock {
Subroutine _unlock: not called CC=1 SCAR=6.9
104 0 my $self = shift;
105 0 my $lockfile = catfile($self->RootDirectory, $self->LockFile);
106 0 flock(LOCK, LOCK_UN);
107 0 close LOCK;
108 }
109  
110 0 ▶sub children_ids {
Subroutine children_ids: not called CC=10 SCAR=47.0
Pod undocumented
111 0 my($self, $obj_id) = @_;
112 0 $self->idify_params($obj_id);
113 0 my $dir = $self->_abs_filename($obj_id);
114 0 my @children;
115 0 ▶ if (opendir(DIR, $dir)) {
Branch: 1 branch
BranchTrueFalseTotal
if (opendir DIR, $dir) { } 0 0 0
116 0 my $f;
117 0 ▶ while(defined($f = readdir DIR)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($f = readdir DIR)) 0 0 0
118 0 ▶ next if $f eq '.' || $f eq '..';
Branch: 1 branch
BranchTrueFalseTotal
if $f eq "." or $f eq ".." 0 0 0
Condition0%0/3
$f eq "." or $f eq ".."
l!l&&r!l&&!r
000
MC/DC0%0/2
$f eq "." or $f eq ".."
$f eq "." $f eq ".."
Truth table0%0/3
A or B
A= $f eq "."B= $f eq ".."
ABresult
1X1
011
000
119 # XXX skip expect ...
120 0 ▶ next if $f eq '.lock'; # XXX use LockFile...
Branch: 1 branch
BranchTrueFalseTotal
if $f eq ".lock" 0 0 0
121 0 ▶ next if $f =~ /^\.meta/; # XXX use MetaPrefix/Suffix...
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /^\.meta/ 0 0 0
122 0 ▶ next if $f eq 'db' && $self->is_root_object($obj_id); # XXX exclude db
Branch: 1 branch
BranchTrueFalseTotal
if $f eq "db" and $self->is_root_object($obj_id) 0 0 0
Condition0%0/3
$f eq "db" and $self->is_root_object($obj_id)
!ll&&!rl&&r
000
MC/DC0%0/2
$f eq "db" and $self->is_root_object($obj_id)
$f eq "db" $self->is_root_object($obj_id)
Truth table0%0/3
A and B
A= $f eq "db"B= $self->is_root_object($obj_id)
ABresult
0X0
100
111
123 0 ▶ next if $f =~ /^(RCS|CVS|\.svn)$/; # XXX should be determined from $self->VCS
Branch: 1 branch
BranchTrueFalseTotal
if $f =~ /^(RCS|CVS|\.svn)$/ 0 0 0
124 0 push @children, $obj_id . "/" . $f;
125 }
126 0 closedir DIR;
127 } else {
128 #warn "Can't open $dir: $!";
129 }
130 0 @children;
131 }
132  
133 0 ▶sub parent_ids {
Subroutine parent_ids: not called CC=2 SCAR=17.9
Pod undocumented
134 0 my($self, $obj_id) = @_;
135 0 my @ret;
136 0 $self->idify_params($obj_id);
137 0 ▶ if (!$self->is_root_object($obj_id)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_root_object($obj_id)) 0 0 0
138 0 @ret = dirname($obj_id);
139 }
140 0 @ret; # XXX does not handle symlinks yet
141 }
142  
143 0 ▶sub version_ids {
Subroutine version_ids: not called CC=4 SCAR=30.0
Pod undocumented
144 0 my($self, $obj_id) = @_;
145 0 my @ret;
146 0 ▶ return @ret if (!defined $self->VCS);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->VCS 0 0 0
147 0 $self->idify_params($obj_id);
148 0 my $vcs = $self->_get_vcs_object($obj_id);
149 0 ▶ if (defined $vcs) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vcs) 0 0 0
150 0 my $base = $self->_filename($obj_id);
151 0 for my $version ($vcs->versions) {
152 0 push @ret, "version:" . $version->version . ";" . $base;
153 }
154 }
155 0 @ret;
156 }
157  
158 # different signature from WE::DB::Obj
159 0 ▶sub _next_id {
Subroutine _next_id: not called CC=9 SCAR=45.0
160 0 my($self, $parent_id, $basename) = @_;
161 0 ▶ if (!defined $basename || $basename eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $basename or $basename eq '') { } 0 0 0
Condition0%0/3
not defined $basename or $basename eq ""
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $basename or $basename eq ""
not defined $basename $basename eq ""
Truth table0%0/3
not(A) or B
A= not defined $basenameB= $basename eq ""
ABresult
1X1
011
000
162 0 $basename = "0000";
163 } else {
164 0 my $file = $self->_abs_filename("$parent_id/$basename");
165 0 ▶ if (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file) { } 0 0 0
166 0 ▶ if ($basename !~ /_\d{4}$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($basename =~ /_\d{4}$/) 0 0 0
167 0 $basename .= "_0000";
168 }
169 } else {
170 0 my $meta_file = $self->_abs_meta_filename("$parent_id/$basename");
171 0 ▶ if (-e $meta_file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $meta_file) 0 0 0
172 0 ▶ if ($basename !~ /_\d{4}$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($basename =~ /_\d{4}$/) 0 0 0
173 0 $basename .= "_0000";
174 }
175 }
176 }
177 }
178 0 while(1) {
179 0 my $file = $self->_abs_filename("$parent_id/$basename");
180 0 ▶ if (!-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
181 0 my $meta_file = $self->_abs_meta_filename("$parent_id/$basename");
182 0 ▶ if (!-e $meta_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $meta_file) 0 0 0
183 0 return "$parent_id/$basename";
184 }
185 }
186 0 $basename++;
187 }
188 }
189  
190 0 ▶sub _store_meta_object {
Subroutine _store_meta_object: not called CC=2 SCAR=17.9
191 0 my($self, $obj) = @_;
192 0 my $meta_file = $self->_abs_meta_filename($obj->Id);
193 0 ▶ open(META, ">$meta_file") or die "Can't write $meta_file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open META, ">$meta_file" or die "Can't write ${meta_file}: $!" 0 0 0
194 0 print META YAML::Dump($obj);
195 0 close META;
196 }
197  
198 0 ▶sub _get_vcs_object {
Subroutine _get_vcs_object: not called CC=6 SCAR=37.4
199 0 my($self, $obj_id, $version_number, $non_meta) = @_;
200 0 require VCS;
201 0 ▶ my $file = ($non_meta ? $self->_abs_filename($obj_id) : $self->_abs_meta_filename($obj_id));
Branch: 1 branch
BranchTrueFalseTotal
$non_meta ? : 0 0 0
202 0 ▶ if ($self->VCS eq 'RCS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->VCS eq "RCS") 0 0 0
203 0 my $rcs_dir = catfile(dirname($file), "RCS");
204 0 ▶ if (!-e $rcs_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $rcs_dir) 0 0 0
205 0 return undef;
206 }
207 0 ▶ if (!-e catfile($rcs_dir, basename($file).",v")) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e catfile($rcs_dir, basename($file) . ',v')) 0 0 0
208 0 return undef;
209 }
210 }
211 0 my $vcs_url = "vcs://localhost/VCS::" . ucfirst(lc($self->VCS)) . $file;
212 0 %VCS::Rcs::LOG_CACHE = (); # XXX
213 0 ▶ if (defined $version_number) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $version_number) { } 0 0 0
214 0 VCS::Version->new($vcs_url . "/" . $version_number);
215 } else {
216 0 VCS::File->new($vcs_url);
217 }
218 }
219  
220 0 ▶sub _get_meta_object {
Subroutine _get_meta_object: not called CC=9 SCAR=45.0
221 0 my($self, $id) = @_;
222 0 my $meta_file;
223 my $version_number;
224 0 my $version_info = [];
225 0 my $version_obj;
226 my $ret;
227 0 ▶ if ($self->is_version($id, $version_info)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_version($id, $version_info)) { } 0 0 0
228 0 $version_number = $version_info->[0];
229 0 $version_obj = $self->_get_vcs_object($id, $version_number);
230 0 ▶ if ($version_obj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version_obj) { } 0 0 0
231 0 my $buf = $version_obj->text;
232 0 $ret = YAML::Load($buf);
233 } else {
234 0 warn "Can't get VCS object for $id, version $version_number";
235 }
236 } else {
237 0 $meta_file = $self->_abs_meta_filename($id);
238  
239 0 ▶ if (open(META, $meta_file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open META, $meta_file) 0 0 0
240 0 local $/ = undef;
241 0 my $buf = <META>;
242 0 close META;
243 0 $ret = YAML::Load($buf);
244 }
245 }
246  
247 0 ▶ if (!$ret) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret) 0 0 0
248 0 my $file = $self->_abs_filename($id);
249 0 ▶ if ($id eq 'file:') { # fake root object
Branch: 3 branches
BranchTrueFalseTotal
if ($id eq 'file:') { } 0 0 0
elsif (-d $file) { } 0 0 0
elsif (-f $file) { } 0 0 0
250 0 $ret = WE::Obj::Site->new;
251 0 $ret->Id($id);
252 0 $ret->Title("Root of the site");
253 } elsif (-d $file) {
254 0 $ret = WE::Obj::Folder->new;
255 0 $ret->Id($id);
256 } elsif (-f $file) {
257 0 $ret = WE::Obj::Doc->new;
258 0 $ret->Id($id);
259 } else {
260 #warn "Neither can open $meta_file nor $file: $!";
261 }
262 }
263  
264 0 ▶ if ($version_obj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version_obj) 0 0 0
265 # Version pseudo attributes (unchangeable!)
266 0 $ret->Version_Number($version_number);
267 0 $ret->Version_Owner($ret->Owner);
268 0 $ret->Version_Comment($version_obj->reason);
269 0 $ret->Version_Parent($ret->Id);
270 0 $ret->Id("version:$version_number;" . $self->_filename($ret->Id));
271 }
272  
273 0 $ret;
274 }
275  
276 0 ▶sub _filename {
Subroutine _filename: not called CC=3 SCAR=24.8
277 0 my($self, $id) = @_;
278 0 my($type, $rest) = $id =~ /^([^:]+):(.*)/; # "file:/path/to/file"
279 0 my $base;
280 0 ▶ if ($type eq 'file') {
Branch: 2 branches
BranchTrueFalseTotal
if ($type eq 'file') { } 0 0 0
elsif ($type eq 'version') { } 0 0 0
281 0 $base = $rest;
282 } elsif ($type eq 'version') {
283 0 my($ver, $file) = $rest =~ /^([^;]+);(.*)/; # "version:1.2,/path/to/file"
284 0 $base = $file;
285 } else {
286 0 die "Unrecognized type <$type> from id <$id>";
287 }
288 0 $base;
289 }
290  
291 0 ▶sub _abs_filename {
Subroutine _abs_filename: not called CC=1 SCAR=6.9
292 0 my($self, $id) = @_;
293 0 canonpath(catfile($self->RootDirectory, $self->_filename($id)));
294 }
295  
296 0 ▶sub _abs_meta_filename {
Subroutine _abs_meta_filename: not called CC=1 SCAR=6.9
297 0 my($self, $id) = @_;
298 0 my $file = $self->_filename($id);
299 0 canonpath(catfile($self->RootDirectory,
300 dirname($file),
301 join("", $self->MetaPrefix, basename($file), $self->MetaSuffix)));
302 }
303  
304 0 ▶sub insert_doc {
Subroutine insert_doc: not called CC=10 SCAR=47.0
Pod undocumented
305 0 my($self, %args) = @_;
306 0 my $doc = WE::Obj::Doc->new;
307 # XXX permission manager
308 0 my $content = delete $args{-content};
309 0 my $file = delete $args{-file};
310 0 my $parent = delete $args{-parent};
311 0 ▶ while(my($k,$v) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
312 0 ▶ die "Option does not start with a dash: $k" if $k !~ /^-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^-/ 0 0 0
313 0 $doc->{ucfirst(substr($k,1))} = $v;
314 }
315 0 ▶ if (defined $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 0 0 0
316 0 ▶ $doc->{ContentType} = get_mime_type_by_filename($file) if !$doc->{ContentType};
Branch: 1 branch
BranchTrueFalseTotal
unless $doc->{"ContentType"} 0 0 0
317 0 ▶ open(F, $file) or die "Can't open file $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open F, $file or die "Can't open file ${file}: $!" 0 0 0
318 0 local $/ = undef;
319 0 $content = <F>;
320 0 close F;
321  
322 0 require File::Basename;
323 0 my $base = File::Basename::basename($file);
324  
325 # auto set title
326 0 ▶ if (!defined $doc->{Title}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $doc->{"Title"}) 0 0 0
327 0 ▶ if ($base =~ /^(.+)(\.[^.]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base =~ /^(.+)(\.[^.]+)$/) { } 0 0 0
328 0 $doc->{Title} = $1; # stripped extension
329 } else {
330 0 $doc->{Title} = $base; # there is no extension
331 }
332 }
333  
334 0 ▶ if (!defined $doc->{Basename}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $doc->{"Basename"}) 0 0 0
335 0 $doc->{Basename} = $base;
336 }
337 }
338  
339 0 ▶ $doc->ContentType("text/html") if !$doc->{ContentType}; # i.e. content given
Branch: 1 branch
BranchTrueFalseTotal
unless $doc->{"ContentType"} 0 0 0
340 0 $self->insert($doc, -parent => $parent);
341 0 $self->_store_content($doc, $content);
342 0 $doc;
343 }
344  
345 0 ▶sub insert_folder {
Subroutine insert_folder: not called CC=3 SCAR=24.8
Pod undocumented
346 0 my($self, %args) = @_;
347 0 my $folder = WE::Obj::Folder->new;
348 # XXX permission manager
349 0 my $parent = delete $args{-parent};
350 0 ▶ while(my($k,$v) = each %args) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 0 0 0
351 0 ▶ die "Option does not start with a dash: $k" if $k !~ /^-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $k =~ /^-/ 0 0 0
352 0 $folder->{ucfirst(substr($k,1))} = $v;
353 }
354  
355 0 $folder = $self->insert($folder, -parent => $parent);
356 0 $folder;
357 }
358  
359 0 ▶sub insert {
Subroutine insert: not called CC=1 SCAR=6.9
Pod undocumented
360 0 my($self, $obj, %args) = @_;
361  
362 0 ▶ $self->connect_if_necessary(sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
363 0 my $parent = delete $args{-parent};
364 0 ▶ if (!defined $parent) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $parent) 0 0 0
365 0 die "The -parent option is missing";
366 }
367 0 $self->idify_params($parent);
368 0 my $id = $self->_next_id($parent, $obj->{Basename});
369  
370 0 my $parent_obj = $self->get_object($parent);
371 0 ▶ if (!$parent_obj->isa("WE::Obj::FolderObj")) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_obj->isa("WE::Obj::FolderObj")) 0 0 0
372 0 die "The object with the id $parent is not a FolderObj, but a " . ref $parent_obj . ". Objects can only be inserted in folders.";
373 }
374 0 ▶ if (!$parent_obj->object_is_insertable($obj)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_obj->object_is_insertable($obj)) 0 0 0
375 0 die "The object type " . ref($obj) . " is not allowed in " . ref($parent_obj) . ". The only allowed object types are: " . join(", ", @{ $parent_obj->insertable_types });
376 }
377  
378 0 $obj->Id($id);
379 0 my $owner = $self->Root->CurrentUser;
380 0 ▶ if (defined $owner) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $owner) { } 0 0 0
381 0 $obj->Owner($owner);
382 } else {
383 0 $obj->Owner(undef); # no owner
384 }
385 0 my $now = epoch2isodate();
386 0 $obj->TimeCreated($now);
387 0 $obj->TimeModified($now);
388  
389 0 $self->_store_meta_object($obj);
390  
391 0 ▶ if ($obj->is_folder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->is_folder) 0 0 0
392 0 my $dir = $self->_abs_filename($obj->Id);
393 0 mkdir $dir, 0775; # XXX mode, check etc.
394 }
395  
396 # update names, links ...
397 0 ▶ if ($self->Root->NameDB) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Root->NameDB) 0 0 0
398 0 $self->Root->NameDB->update([$obj],[]);
399 }
400 0 });
401  
402 0 $obj;
403 }
404  
405 0 ▶sub get_object {
Subroutine get_object: not called CC=1 SCAR=6.9
Pod undocumented
406 0 my($self, $obj_id) = @_;
407 0 $self->_get_meta_object($obj_id);
408 }
409  
410 0 ▶sub root_object {
Subroutine root_object: not called CC=1 SCAR=6.9
Pod undocumented
411 0 my($self) = @_;
412 0 $self->get_object("file:");
413 }
414  
415 0 ▶sub is_root_object {
Subroutine is_root_object: not called CC=1 SCAR=6.9
Pod undocumented
416 0 my($self, $objid) = @_;
417 0 $self->idify_params($objid);
418 0 $objid eq 'file:';
419 }
420  
421 0 ▶sub is_version {
Subroutine is_version: not called CC=3 SCAR=24.8
Pod undocumented
422 0 my($self, $objid, $ver_info_ref) = @_;
423 0 ▶ if ($objid =~ /^version:([^;]+);(.*)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($objid =~ /^version:([^;]+);(.*)/) { } 0 0 0
424 0 ▶ if ($ver_info_ref) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ver_info_ref) 0 0 0
425 0 @$ver_info_ref = ($1, $2);
426 }
427 0 1;
428 } else {
429 0 0;
430 }
431 }
432  
433 0 ▶sub content {
Subroutine content: not called CC=5 SCAR=34.0
Pod undocumented
434 0 my($self, $objid) = @_;
435  
436 0 my $obj;
437 0 ▶ if (ref $objid) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $objid) { } 0 0 0
438 0 $obj = $objid;
439 0 $objid = $obj->Id;
440 } else {
441 0 $obj = $self->get_object($objid);
442 }
443  
444 0 my $file = $self->_abs_filename($objid);
445 0 ▶ if (-d $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) 0 0 0
446 0 die "Can't get content for object <$objid>";
447 }
448  
449 0 my $content;
450 0 my $version_info = [];
451 0 ▶ if ($self->is_version($objid, $version_info)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_version($objid, $version_info)) { } 0 0 0
452 0 $content = $self->_get_vcs_object($objid, $version_info->[0], 'non-meta')->text;
453 } else {
454 0 ▶ open(F, $file) or die "Can't get content from file <$file> for object <$objid>: $!";
Branch: 1 branch
BranchTrueFalseTotal
open F, $file or die "Can't get content from file <$file> for object <$objid>: $!" 0 0 0
455 0 local $/ = undef;
456 0 $content = <F>;
457 0 close F;
458 }
459 0 $content;
460 }
461  
462 1 *get_content = \&content;
463  
464 0 ▶sub _store_content {
Subroutine _store_content: not called CC=2 SCAR=17.9
465 0 my($self, $obj_id, $content) = @_;
466 0 $self->idify_params($obj_id);
467 0 my $file = $self->_abs_filename($obj_id);
468 0 ▶ open(F, ">$file") or die "Can't write content for object <$obj_id>: $!";
Branch: 1 branch
BranchTrueFalseTotal
open F, ">$file" or die "Can't write content for object <$obj_id>: $!" 0 0 0
469 0 print F $content;
470 0 close F;
471 }
472  
473 0 ▶sub remove {
Subroutine remove: not called CC=1 SCAR=6.9
Pod undocumented
474 0 my($self, $obj_id) = @_;
475 0 $self->idify_params($obj_id);
476 $self->connect_if_necessary
477 0 ▶ (sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
478 0 my $file = $self->_abs_filename($obj_id);
479 0 my $meta_file = $self->_abs_meta_filename($obj_id);
480 0 my $o = $self->get_object($obj_id);
481  
482 # unlink children
483 0 ▶ if ($o->is_folder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o->is_folder) 0 0 0
484 0 foreach my $child_id ($self->children_ids($obj_id)) {
485 # XXX can't unlink yet
486 0 $self->remove($child_id);
487 }
488 }
489  
490 # delete everything in name database
491 0 ▶ if ($self->Root->NameDB) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->Root->NameDB) 0 0 0
492 0 $self->Root->NameDB->update([], [$o]);
493 }
494  
495 # delete physical object
496 0 ▶ if (-d $file) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $file) { } 0 0 0
497 0 rmdir $file;
498 } else {
499 0 unlink $file;
500 }
501 0 unlink $meta_file;
502  
503 # # delete remaining links
504 # my @obj_ids = $self->find_links($obj_id);
505 # foreach my $id (@obj_ids) {
506 # my $stored_obj = $self->_get_stored_obj($id);
507 # $self->_remove_from_link_array($obj_id, $stored_obj);
508 # $self->_store_stored_obj($stored_obj);
509 # }
510  
511 0 });
512 }
513  
514 0 ▶sub replace_object {
Subroutine replace_object: not called CC=3 SCAR=24.8
Pod undocumented
515 0 my($self, $obj) = @_;
516 # XXX permission manager
517 0 my $old_obj = $self->_get_meta_object($obj->Id);
518 0 ▶ die "Can't get meta object from id " . $obj->Id if !$old_obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $old_obj 0 0 0
519 0 $obj->TimeModified(epoch2isodate());
520 0 $obj->Dirty(1);
521 0 $obj->DirtyAttributes(1);
522 0 $self->_store_meta_object($obj);
523  
524 # update names, links ...
525 0 my $namedb = $self->Root->NameDB;
526 0 ▶ if ($namedb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($namedb) 0 0 0
527 0 $namedb->update([$obj],[$old_obj]);
528 }
529  
530 0 $obj;
531 }
532  
533 0 ▶sub replace_content {
Subroutine replace_content: not called CC=2 SCAR=17.9
Pod undocumented
534 0 my($self, $objid, $new_content) = @_;
535 0 $self->idify_params($objid);
536 0 ▶ my $obj = $self->get_object($objid) || die "Can't get object for id $objid";
Condition0%0/2
$self->get_object($objid) || die("Can't get object for id $objid")
l!l
00
MC/DC0%0/1
$self->get_object($objid) || die("Can't get object for id $objid")
$self->get_object($objid)
Truth table0%0/2
A
A= $self->get_object($objid)
Aresult
11
00
537 0 $obj->TimeModified(epoch2isodate());
538 0 $obj->Dirty(1);
539 0 $obj->DirtyContent(1);
540 0 $self->_store_meta_object($obj);
541 0 $self->_store_content($objid, $new_content);
542 0 $obj;
543 }
544  
545 0 ▶sub exists {
Subroutine exists: not called CC=1 SCAR=6.9
Pod undocumented
546 0 my($self, $obj_id) = @_;
547 0 $self->idify_params($obj_id);
548 0 defined $self->_get_meta_object($obj_id);
549 }
550  
551 # Different return value: return object id for moved object
552 0 ▶sub move {
Subroutine move: not called CC=7 SCAR=40.3
Pod undocumented
553 0 my($self, $objid, $parentid, %args) = @_;
554 0 $self->idify_params($objid);
555 # if (!defined $parentid) {
556 # $parentid = ($self->parent_ids($objid))[0];
557 # }
558 # $self->idify_params($parentid);
559  
560 0 my $destination = delete $args{-destination};
561 0 ▶ if (!defined $destination) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $destination) 0 0 0
562 0 $destination = delete $args{-target}; # Alias for -destination
563 }
564 0 my $after = delete $args{-after};
565 0 ▶ if (defined $after) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $after) 0 0 0
566 0 die "-after NYI";
567 }
568 0 my $before = delete $args{-before};
569 0 ▶ if (defined $before) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $before) 0 0 0
570 0 die "-before NYI";
571 }
572 0 my $to = delete $args{-to};
573 0 ▶ if (defined $to) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $to) 0 0 0
574 0 die "-to NYI";
575 }
576 0 ▶ if (defined $destination) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $destination) { } 0 0 0
577 0 $self->idify_params($destination);
578 0 my $src_file = $self->_abs_filename($objid);
579 0 my $src_meta_file = $self->_abs_meta_filename($objid);
580 0 my $dest_dir = $self->_abs_filename($destination);
581 0 ▶ if (!-d $dest_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $dest_dir) 0 0 0
582 0 die "Destination is not a directory";
583 }
584 0 my $dest_id = $self->_next_id($destination, basename($src_file));
585 0 my $dest_file = $self->_abs_filename($dest_id);
586 0 my $dest_meta_file = $self->_abs_meta_filename($dest_id);
587 0 File::Copy::move($src_file, $dest_file);
588 0 File::Copy::move($src_meta_file, $dest_meta_file);
589 0 $self->_repair_meta_data($dest_id);
590 0 ▶ $self->walk($dest_id, sub { $self->_repair_meta_data($_[0]) });
Subroutine __ANON__: not called CC=1 SCAR=6.9
591 0 $dest_id;
592 } else {
593 0 die "Nowhere to move. Please specify either -destination, -before or -after";
594 }
595 }
596  
597 0 ▶sub copy {
Subroutine copy: not called CC=1 SCAR=6.9
Pod undocumented
598 0 my($self, $object_id, $target_id, %args) = @_;
599 0 $self->_copy($object_id, -parent => $target_id, %args);
600 }
601  
602 0 ▶sub _copy {
Subroutine _copy: not called CC=10 SCAR=47.0
603 0 my($self, $object_id, %args) = @_;
604 0 $self->idify_params($object_id);
605 0 my $obj = $self->get_object($object_id);
606 0 ▶ require Carp, Carp::croak("Can't find object with id $object_id") if !$obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $obj 0 0 0
607  
608 0 my %insert_args;
609 my $insert_meth;
610 0 ▶ if (defined $args{-parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'-parent'}) { } 0 0 0
611 0 my $target_id = delete $args{-parent};
612 0 $self->idify_params($target_id);
613 0 my $target_obj = $self->get_object($target_id);
614 0 ▶ die "Target must be a folder" if !$target_obj->is_folder;
Branch: 1 branch
BranchTrueFalseTotal
unless $target_obj->is_folder 0 0 0
615 0 %insert_args = (-parent => $target_id, %args);
616 0 $insert_meth = "insert";
617 } else { # new version
618 0 my $version_parent_id = delete $args{-versionparent};
619 0 $self->idify_params($version_parent_id);
620 0 my $target_obj = $self->get_object($version_parent_id);
621 0 ▶ die "Target $version_parent_id does not exist" if !$target_obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $target_obj 0 0 0
622 0 %insert_args = (-versionparent => $version_parent_id, %args);
623 0 $insert_meth = "_insert_version";
624 }
625  
626 0 ▶ if ($obj->is_doc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj->is_doc) { } 0 0 0
627 0 my $content = $self->content($object_id);
628 0 my $clone_obj = $obj->clone;
629 #XXX if (grep($_ eq $target_id, $self->parent_ids($object_id))) {
630 # # XXX NYI: change title to "Copy of ..." (lang-dependent)
631 # }
632 0 $self->$insert_meth($clone_obj, %insert_args);
633 0 $self->replace_content($clone_obj, $content);
634 0 $clone_obj;
635 } else { # copy folder
636 0 my $clone_obj = $obj->clone;
637 #XXX if (grep($_ eq $target_id, $self->parent_ids($object_id))) {
638 # # XXX NYI: change title to "Copy of ..." (lang-dependent)
639 # }
640 0 my @ret;
641 0 $self->$insert_meth($clone_obj, %insert_args);
642 0 push @ret, $clone_obj;
643 0 ▶ if (!exists $args{-recursive} || $args{-recursive}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $args{"-recursive"} or $args{"-recursive"}) 0 0 0
Condition0%0/3
not exists $args{"-recursive"} or $args{"-recursive"}
l!l&&r!l&&!r
000
MC/DC0%0/2
not exists $args{"-recursive"} or $args{"-recursive"}
not exists $args{"-recursive"} $args{"-recursive"}
Truth table0%0/3
not(A) or B
A= not exists $args{"-recursive"}B= $args{"-recursive"}
ABresult
1X1
011
000
644 0 foreach my $child_id ($self->children_ids($object_id)) {
645 0 ▶ if (exists $insert_args{-parent}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $insert_args{'-parent'}) { } 0 0 0
646 0 $insert_args{-parent} = $clone_obj->Id;
647 } else {
648 0 $insert_args{-versionparent} = $clone_obj->Id;
649 }
650 0 push @ret, $self->_copy($child_id, %insert_args);
651 }
652 }
653 0 @ret;
654 }
655 }
656  
657 0 ▶sub _repair_meta_data {
Subroutine _repair_meta_data: not called CC=3 SCAR=24.8
658 0 my($self, $obj_id) = @_;
659 0 $self->idify_params($obj_id);
660 0 my $o = $self->_get_meta_object($obj_id);
661 0 my $changed = 0;
662 0 ▶ if ($obj_id ne $o->Id) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj_id ne $o->Id) 0 0 0
663 0 $o->Id($obj_id);
664 0 $changed++;
665 }
666 0 ▶ if ($changed) {
Branch: 1 branch
BranchTrueFalseTotal
if ($changed) 0 0 0
667 0 $self->_store_meta_object($o);
668 }
669 }
670  
671 0 ▶sub ci {
Subroutine ci: not called CC=19 SCAR=59.4
Pod undocumented
672 0 my($self, $obj_id, %args) = @_;
673 0 $self->idify_params($obj_id);
674 0 ▶ if (defined $args{-version}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"-version"}) 0 0 0
675 0 $args{-number} = delete $args{-version};
676 }
677 0 ▶ if (defined $args{-comment}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"-comment"}) 0 0 0
678 0 $args{-log} = delete $args{-comment};
679 }
680 0 my $trimold = delete $args{-trimold};
681 0 my @ret;
682  
683 0 ▶ if ($self->VCS eq 'RCS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->VCS eq 'RCS') { } 0 0 0
684 0 my @ci_args;
685 0 ▶ if (defined $args{-number}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{'-number'}) { } 0 0 0
686 0 push @ci_args, "-l" . $args{-number};
687 } else {
688 0 push @ci_args, "-l";
689 }
690 0 ▶ if (defined $args{-log}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"-log"}) 0 0 0
691 0 push @ci_args, "-m" . $args{-log}, "-f";
692 }
693 0 my $file = $self->_abs_filename($obj_id);
694 0 my $meta_file = $self->_abs_meta_filename($obj_id);
695  
696 0 my $rcs_dir = catfile(dirname($meta_file), "RCS");
697 0 ▶ if (!-d $rcs_dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $rcs_dir) 0 0 0
698 0 mkdir $rcs_dir, 0775; # XXX check; mode
699 }
700  
701 0 my($meta_ver, $ver, $_log);
702  
703 0 ▶ my $parse_for_versions = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
704 0 my $fh = shift;
705 0 $_log = "";
706 0 ▶ while(<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
707 0 $_log .= $_;
708 0 ▶ if (/new revision:\s+([\d.]+)/) {
Branch: 3 branches
BranchTrueFalseTotal
if (/new revision:\s+([\d.]+)/) { } 0 0 0
elsif (/initial revision:\s+([\d.]+)/) { } 0 0 0
elsif (/file is unchanged; reverting to previous revision\s+([\d.]+)/) { } 0 0 0
709 0 return $1;
710 } elsif (/initial revision:\s+([\d.]+)/) {
711 0 return $1;
712 } elsif (/file is unchanged; reverting to previous revision\s+([\d.]+)/) {
713 0 return $1;
714 }
715 }
716 0 undef;
717 0 };
718  
719 0 ▶ open(CI, "-|") or do {
Branch: 1 branch
BranchTrueFalseTotal
open CI, "-|" or do { open STDIN, '<' . "File::Spec"->devnull or die $!; open STDERR, ">&STDOUT" or die $!; exec "ci", @ci_args, $meta_file; die $! } 0 0 0
720 0 ▶ open(STDIN, "<" . File::Spec->devnull) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, '<' . "File::Spec"->devnull or die $! 0 0 0
721 0 ▶ open(STDERR, ">&STDOUT") or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&STDOUT" or die $! 0 0 0
722 0 exec("ci", @ci_args, $meta_file);
723 0 die $!;
724 };
725 0 $meta_ver = $parse_for_versions->(\*CI);
726 0 close CI;
727 0 ▶ if (!defined $meta_ver) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $meta_ver) 0 0 0
728 0 warn "Can't get version for $meta_file. Log is <$_log>";
729 }
730  
731 0 ▶ if (!-d $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $file) 0 0 0
732 0 ▶ open(CI, "-|") or do {
Branch: 1 branch
BranchTrueFalseTotal
open CI, "-|" or do { open STDIN, '<' . "File::Spec"->devnull or die $!; open STDERR, ">&STDOUT" or die $!; exec "ci", @ci_args, $file; die $! } 0 0 0
733 0 ▶ open(STDIN, "<" . File::Spec->devnull) or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open STDIN, '<' . "File::Spec"->devnull or die $! 0 0 0
734 0 ▶ open(STDERR, ">&STDOUT") or die $!;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&STDOUT" or die $! 0 0 0
735 0 exec("ci", @ci_args, $file);
736 0 die $!;
737 };
738 0 $ver = $parse_for_versions->(\*CI);
739 0 close CI;
740 0 ▶ if (!defined $ver) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $ver) { } 0 0 0
741 0 warn "Can't get version for $file. Log is <$_log>";
742 } else {
743 0 ▶ if ($ver ne $meta_ver) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ver ne $meta_ver) 0 0 0
744 0 warn "Versions for file and meta file differ: $ver != $meta_ver";
745 }
746 }
747  
748 0 push @ret, "version:$meta_ver;" . $self->_filename($obj_id);
749 }
750  
751 } else {
752 0 die "VCS type " . $self->VCS . " not yet implemented";
753 }
754  
755 0 ▶ if ($trimold) {
Branch: 1 branch
BranchTrueFalseTotal
if ($trimold) 0 0 0
756 #XXX not yet implemented: $self->trim_old_versions($obj_id, -trimold => $trimold);
757 }
758  
759 0 $self->_undirty($obj_id);
760  
761 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 0 0
762 0 map { $self->get_object($_) } @ret;
763 } else {
764 0 $self->get_object($ret[0]);
765 }
766 }
767  
768 0 ▶sub co {
Subroutine co: not called CC=10 SCAR=47.0
Pod undocumented
769 0 my($self, $obj_id, %args) = @_;
770 0 $self->idify_params($obj_id);
771 0 ▶ if (defined $args{-version}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"-version"}) 0 0 0
772 0 $args{-number} = delete $args{-version};
773 }
774 0 my $v_obj;
775 0 ▶ if (!defined $args{-number}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"-number"}) 0 0 0
776 0 my @v_id = $self->version_ids($obj_id);
777 0 ▶ if (!@v_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@v_id) 0 0 0
778 0 die "There are no versions available for object $obj_id";
779 }
780 0 $v_obj = $self->get_object($v_id[-1]);
781 }
782 0 ▶ if (!$v_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v_obj) 0 0 0
783 0 foreach my $v ($self->versions($obj_id)) {
784 0 ▶ if ($v->Version_Number eq $args{-number}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v->Version_Number eq $args{"-number"}) 0 0 0
785 0 $v_obj = $v;
786 0 last;
787 }
788 }
789 }
790 0 ▶ if (!$v_obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($v_obj) 0 0 0
791 0 die "Can't find version $args{-number} for object $obj_id";
792 }
793  
794 0 ▶ if ($self->VCS eq 'RCS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->VCS eq 'RCS') { } 0 0 0
795 0 my $file = $self->_abs_filename($obj_id);
796 0 my $meta_file = $self->_abs_meta_filename($obj_id);
797 # XXX redirect stderr, check error messages
798 0 system("rcs", "-u", $file); # unlock
799 0 my @co_args = ("-f", "-l");
800 0 ▶ if (defined $args{-number}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"-number"}) 0 0 0
801 0 push @co_args, "-r".$args{-number};
802 }
803 0 system("co", @co_args, $file);
804 0 system("co", @co_args, $meta_file);
805 } else {
806 0 die "VCS type " . $self->VCS . " not yet implemented";
807 }
808  
809 0 $self->get_object($v_obj->Version_Parent);
810 }
811  
812 # XXX does not use symlink information for multiple parents
813 0 ▶sub depth {
Subroutine depth: not called CC=1 SCAR=6.9
Pod undocumented
814 0 my($self, $objid) = @_;
815 0 $self->idify_params($objid);
816 0 my $file = $self->_filename($objid);
817 # XXX canonify path?
818 0 my $depth = $file =~ tr|/|/|;
819 0 ($depth+1, $depth+1);
820 }
821  
822 # XXX does not handle version ids (I think)
823 0 ▶sub pathname {
Subroutine pathname: not called CC=3 SCAR=24.8
Pod undocumented
824 0 my($self, $obj, $parent_obj) = @_;
825 0 $self->idify_params($obj, $parent_obj);
826 0 my $pathname = $obj;
827 0 ▶ if (defined $parent_obj) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $parent_obj) { } 0 0 0
828 0 ($pathname = $obj) =~ s/^\Q$parent_obj\///;
829 } else {
830 0 $pathname =~ s/^file://;
831 }
832 0 ▶ if ($pathname eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pathname eq "") 0 0 0
833 0 $pathname = '/';
834 }
835 0 $pathname;
836 }
837  
838 0 ▶sub pathname2id {
Subroutine pathname2id: not called CC=3 SCAR=24.8
Pod undocumented
839 0 my($self, $name, $parent) = @_;
840 0 $self->idify_params($parent);
841 0 ▶ my $id = "file:" . ($name eq '/' ? "" : $name);
Branch: 1 branch
BranchTrueFalseTotal
$name eq '/' ? : 0 0 0
842 0 ▶ if (!$self->exists($id)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->exists($id)) { } 0 0 0
843 0 undef;
844 } else {
845 0 $id;
846 }
847 }
848  
849 0 ▶sub search_fulltext {
Subroutine search_fulltext: not called CC=5 SCAR=34.0
Pod undocumented
850 0 my($self, $term, %args) = @_;
851  
852 my $obj = (defined $args{-scope}
853 ? $self->get_object($args{-scope})
854 0 ▶ : $self->root_object);
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'-scope'} ? : 0 0 0
855 0 ▶ if (!$obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($obj) 0 0 0
856 0 die "Cannot get scoped object";
857 }
858  
859 0 ▶ if (!$args{-regexp}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"-regexp"}) 0 0 0
860 0 $term = "\Q$term";
861 }
862 0 ▶ if (!$args{-casesensitive}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"-casesensitive"}) 0 0 0
863 0 $term = "(?i)$term";
864 }
865  
866 0 delete $args{-scope};
867 0 $self->_search_fulltext($obj, $term, %args);
868 }
869  
870 0 ▶sub _search_fulltext {
Subroutine _search_fulltext: not called CC=5 SCAR=34.0
871 0 my($self, $obj, $term, %args) = @_;
872 0 my @res_ids;
873 0 ▶ if ($obj->is_folder) {
Branch: 2 branches
BranchTrueFalseTotal
if ($obj->is_folder) { } 0 0 0
elsif ($obj->is_doc) { } 0 0 0
874 0 foreach my $s_obj ($self->children($obj)) {
875 0 push @res_ids, $self->_search_fulltext($s_obj, $term, %args);
876 }
877 } elsif ($obj->is_doc) {
878 push @res_ids, $obj->Id
879 0 ▶ if grep { $_ =~ /$term/s } $self->get_content($obj->Id);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ =~ /$term/s;} $self->get_content($obj->Id) 0 0 0
880 }
881 0 @res_ids;
882 }
883  
884 0 ▶sub filename {
Subroutine filename: not called CC=1 SCAR=6.9
Pod undocumented
885 0 my($self, $obj_id) = @_;
886 0 $self->_abs_filename($obj_id);
887 }
888  
889 package WE::DB::FS::ContentDB; # fake package
890  
891 1 ▶use vars qw(@ISA $AUTOLOAD);
Subroutine BEGIN: called CC=1 SCAR=0.0
892  
893 1 @ISA = 'WE::DB::FS';
894  
895 0 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
896 0 shift->{FS}->$AUTOLOAD(@_);
897 }
898  
899 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
900 0 my($class, $fsdb) = @_;
901 0 bless {FS => $fsdb}, $class;
902 }
903  
904 1 1;
905  
906 __END__
« WE/Util/Functions.pm ↑ Summary WebEditor/SystemExplorer.pm »