File Coverage

blib/lib/WE_Multisite/Root.pm
Criterion Covered Total %
statement 12 40 30.0
branch 0 12 0.0
condition n/a
subroutine 4 7 57.1
pod n/a
total 16 59 27.1


line stmt bran cond sub pod time code
1             # -*- perl -*-
2              
3             #
4             # $Id: Root.pm,v 1.6 2003/12/16 15:21:23 eserte Exp $
5             # Author: Slaven Rezic
6             #
7             # Copyright (C) 2001 Online Office Berlin. All rights reserved.
8             # Copyright (C) 2002 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_Multisite::Root;
18              
19             =head1 NAME
20              
21             WE_Multisite::Root - a sample implementation for a multi-site environment
22              
23             =head1 SYNOPSIS
24              
25             $root = new WE_Multisite::Root -rootdir => $root_directory_for_database;
26              
27             =head1 DESCRIPTION
28              
29             A sample instantiation for C for multi-site environments.
30             There is only one UserDB for the whole system, but there is a number
31             of independen site databases (ObjDB and ContentDB).
32              
33             =head1 METHODS
34              
35             =over 4
36              
37             =cut
38              
39 1     1   1439 use base qw(WE::DB);
  1         1  
  1         77  
40 1     1   5 use WE::Obj;
  1         1  
  1         6  
41              
42             WE::Obj->use_classes(':all');
43             WE::DB->use_databases(qw/Obj ComplexUser Content OnlineUser Name/);
44              
45             __PACKAGE__->mk_accessors(qw(DBDir Readonly Locking));
46              
47 1     1   53 use strict;
  1         2  
  1         28  
48 1     1   4 use vars qw($VERSION);
  1         2  
  1         449  
49             $VERSION = sprintf("%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/);
50              
51             sub new {
52 0     0     my($class, %args) = @_;
53 0           my $self = {};
54 0           bless $self, $class;
55              
56 0           my $db_dir = delete $args{-rootdir};
57 0 0         die "No db_dir given" if !defined $db_dir;
58 0           $self->DBDir($db_dir);
59 0 0         my $readonly = defined $args{-readonly} ? delete $args{-readonly} : 0;
60 0 0         if (!$readonly) {
61 0 0         die "$db_dir is not writable" if !-w $db_dir;
62             }
63 0           $self->Readonly($readonly);
64 0 0         my $locking = defined $args{-locking} ? delete $args{-locking} : 1;
65 0           $self->Locking($locking);
66              
67 0           $self->UserDB (WE::DB::ComplexUser->new($self, "$db_dir/userdb.db"));
68 0           $self->OnlineUserDB (WE::DB::OnlineUser->new($self, "$db_dir/onlinedb.db"));
69              
70 0           $self;
71             }
72              
73             sub init {
74 0     0     die "XXX Reimplementation needed!";
75 0           my $self = shift;
76 0           $self->SUPER::init(@_);
77 0           my $u = $self->UserDB;
78             }
79              
80             sub identify {
81 0     0     die "XXX should I use CurrentUser or another member for the user directories?";
82 0           my $self = shift;
83 0           my $r = $self->SUPER::identify(@_);
84 0 0         if ($r) {
85 0           my $user = $self->CurrentUser;
86 0           $self->ObjDB(WE::DB::Obj->new($self, $self->DBDir."/$user/objdb.db",
87             #-serializer => 'Storable',
88             -locking => $self->Locking,
89             -readonly => $self->Readonly,
90             ));
91 0           $self->ContentDB(WE::DB::Content->new($self, $self->DBDir."/$user/content"));
92 0           $self->NameDB(WE::DB::Content->new($self, $self->DBDir."/$user/name.db"));
93             }
94 0           $r;
95             }
96              
97              
98             1;
99              
100             __END__