1 |
#
|
2 |
# ConfigArea.pm
|
3 |
#
|
4 |
# Originally Written by Christopher Williams
|
5 |
#
|
6 |
# Description
|
7 |
#
|
8 |
# Interface
|
9 |
# ---------
|
10 |
# new(ActiveConfig) : A new ConfigArea object
|
11 |
# setup() : setup the configuration area
|
12 |
# location([dir]) : set/return the location of the area
|
13 |
# version([version]) : set/return the version of the area
|
14 |
# name([name]) : set/return the name of the area
|
15 |
# store(location) : store data in file location
|
16 |
# restore(location) : restore data from file location
|
17 |
# meta() : return a description string of the area
|
18 |
# addconfigitem(url) : add a new item to the area
|
19 |
# configitem(@keys) : return a list of fig items that match
|
20 |
# the keys - all if left blank
|
21 |
# parentstore() : set/return the parent ObjectStore
|
22 |
|
23 |
package Configuration::ConfigArea;
|
24 |
use ActiveDoc::ActiveDoc;
|
25 |
require 5.004;
|
26 |
use Utilities::AddDir;
|
27 |
use ObjectUtilities::ObjectStore;
|
28 |
@ISA=qw(ActiveDoc::ActiveDoc ObjectUtilities::StorableObject);
|
29 |
|
30 |
sub init {
|
31 |
my $self=shift;
|
32 |
$self->newparse("init");
|
33 |
$self->newparse("download");
|
34 |
$self->newparse("setup");
|
35 |
$self->addtag("init","project",\&Project_Start,$self,
|
36 |
\&Project_text,$self,"", $self );
|
37 |
$self->addurltags("download");
|
38 |
$self->addtag("download","use",\&Use_download_Start,$self,
|
39 |
"", $self, "",$self);
|
40 |
$self->addurltags("setup");
|
41 |
$self->addtag("setup","use",\&Use_Start,$self, "", $self, "",$self);
|
42 |
}
|
43 |
|
44 |
sub setup {
|
45 |
my $self=shift;
|
46 |
|
47 |
# --- find out the location
|
48 |
my $location=$self->requestoption("area_location",
|
49 |
"Please Enter the location of the directory");
|
50 |
|
51 |
# --- find area directory name , default name projectname_version
|
52 |
my $name=$self->option("area_name");
|
53 |
my $vers=$self->version;
|
54 |
if ( ! defined $name ) {
|
55 |
$name=$self->name();
|
56 |
$vers=~s/^$name_//;
|
57 |
$name=$name."_".$vers;
|
58 |
}
|
59 |
$self->location($location."/".$name);
|
60 |
|
61 |
# make a new store handler
|
62 |
$self->_setupstore();
|
63 |
|
64 |
# --- download everything first
|
65 |
# FIX-ME --- cacheing is broken
|
66 |
$self->parse("download");
|
67 |
|
68 |
# --- and parse the setup file
|
69 |
$self->parse("setup");
|
70 |
|
71 |
# --- store self in original database
|
72 |
$self->parentconfig()->store($self,"ConfigArea",$self->name(),
|
73 |
$self->version());
|
74 |
}
|
75 |
|
76 |
sub _setupstore {
|
77 |
my $self=shift;
|
78 |
|
79 |
# --- make a new ActiveStore at the location and add it to the db list
|
80 |
my $ad=ActiveDoc::ActiveConfig->new($self->location()."/\.SCRAM");
|
81 |
|
82 |
$self->parentconfig($self->config());
|
83 |
# $self->config(Configuration::ConfigureStore->new());
|
84 |
# $self->config()->db("local",$ad);
|
85 |
# $self->config()->db("parent",$self->parentconfig());
|
86 |
# $self->config()->policy("cache","local");
|
87 |
$self->config($ad);
|
88 |
$self->config()->basedoc($self->parentconfig()->basedoc());
|
89 |
}
|
90 |
|
91 |
sub parentconfig {
|
92 |
my $self=shift;
|
93 |
@_?$self->{parentconfig}=shift
|
94 |
:$self->{parentconfig};
|
95 |
}
|
96 |
|
97 |
sub store {
|
98 |
my $self=shift;
|
99 |
my $location=shift;
|
100 |
|
101 |
my $fh=$self->openfile(">".$location);
|
102 |
$self->savevar($fh,"location", $self->location());
|
103 |
$self->savevar($fh,"url", $self->url());
|
104 |
$self->savevar($fh,"name", $self->name());
|
105 |
$self->savevar($fh,"version", $self->version());
|
106 |
$fh->close();
|
107 |
}
|
108 |
|
109 |
sub restore {
|
110 |
my $self=shift;
|
111 |
my $location=shift;
|
112 |
|
113 |
my $fh=$self->openfile("<".$location);
|
114 |
my $varhash={};
|
115 |
$self->restorevars($fh,$varhash);
|
116 |
$self->location($$varhash{"location"});
|
117 |
$self->_setupstore();
|
118 |
$self->url($$varhash{"url"});
|
119 |
$self->name($$varhash{"name"});
|
120 |
$self->version($$varhash{"version"});
|
121 |
$fh->close();
|
122 |
}
|
123 |
|
124 |
sub name {
|
125 |
my $self=shift;
|
126 |
|
127 |
@_?$self->{name}=shift
|
128 |
:$self->{name};
|
129 |
}
|
130 |
|
131 |
sub version {
|
132 |
my $self=shift;
|
133 |
|
134 |
@_?$self->{version}=shift
|
135 |
:$self->{version};
|
136 |
}
|
137 |
|
138 |
sub location {
|
139 |
my $self=shift;
|
140 |
|
141 |
@_?$self->{location}=shift
|
142 |
:$self->{location};
|
143 |
}
|
144 |
|
145 |
sub meta {
|
146 |
my $self=shift;
|
147 |
|
148 |
my $string=$self->name()." ".$self->version()." located at :\n ".
|
149 |
$self->location;
|
150 |
}
|
151 |
|
152 |
sub configitem {
|
153 |
my $self=shift;
|
154 |
my $location=shift;
|
155 |
|
156 |
$self->config()->find("ConfigItem",@_);
|
157 |
}
|
158 |
|
159 |
sub addconfigitem {
|
160 |
my $self=shift;
|
161 |
my $url=shift;
|
162 |
|
163 |
my $docref=$self->activatedoc($url);
|
164 |
# Set up the document
|
165 |
$docref->setup();
|
166 |
# $self->config()->storepolicy("local");
|
167 |
$docref->save();
|
168 |
}
|
169 |
|
170 |
# -------------- Tags ---------------------------------
|
171 |
# -- init parse
|
172 |
sub Project_Start {
|
173 |
my $self=shift;
|
174 |
my $name=shift;
|
175 |
my $hashref=shift;
|
176 |
|
177 |
$self->checktag($name,$hashref,'name');
|
178 |
$self->checktag($name,$hashref,'version');
|
179 |
|
180 |
$self->name($$hashref{'name'});
|
181 |
$self->version($$hashref{'version'});
|
182 |
}
|
183 |
|
184 |
|
185 |
sub Project_text {
|
186 |
my $self=shift;
|
187 |
my $name=shift;
|
188 |
my $string=shift;
|
189 |
|
190 |
print $string;
|
191 |
}
|
192 |
|
193 |
# ---- download parse
|
194 |
|
195 |
sub Use_download_Start {
|
196 |
my $self=shift;
|
197 |
my $name=shift;
|
198 |
my $hashref=shift;
|
199 |
|
200 |
$self->checktag($name,$hashref,'url');
|
201 |
print "Downloading .... ".$$hashref{'url'}."\n";
|
202 |
$self->getfile($$hashref{'url'});
|
203 |
}
|
204 |
|
205 |
# --- setup parse
|
206 |
|
207 |
sub Use_Start {
|
208 |
my $self=shift;
|
209 |
my $name=shift;
|
210 |
my $hashref=shift;
|
211 |
|
212 |
$self->checktag($name,$hashref,'url');
|
213 |
$self->addconfigitem($$hashref{'url'});
|
214 |
}
|
215 |
|