/[cvs]/nfo/perl/libs/Data/Rap.pm
ViewVC logotype

Annotation of /nfo/perl/libs/Data/Rap.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (hide annotations)
Tue May 13 05:52:58 2003 UTC (21 years, 1 month ago) by joko
Branch: MAIN
Changes since 1.6: +29 -3 lines
minor update: modified description printing logic

1 joko 1.1 ## -------------------------------------------------------------------------
2 joko 1.7 ## $Id: Rap.pm,v 1.6 2003/03/29 07:08:56 joko Exp $
3 joko 1.1 ## -------------------------------------------------------------------------
4 joko 1.2 ## $Log: Rap.pm,v $
5 joko 1.7 ## Revision 1.6 2003/03/29 07:08:56 joko
6     ## rap goes global:
7     ## + distinguish between running in global- or project-mode
8     ## + some comments in pod
9     ##
10 joko 1.6 ## Revision 1.5 2003/03/28 16:52:41 jonen
11     ## now using env-var 'RAPBIN'
12     ##
13 jonen 1.5 ## Revision 1.4 2003/03/27 15:31:01 joko
14     ## fixes to modules regarding new namespace(s) below Data::Mungle::*
15     ##
16 joko 1.4 ## Revision 1.3 2003/02/20 18:44:26 joko
17     ## renamed modules
18     ## + sub find_rules: attempts to find 'rap.xml'
19     ## + updated documentation: added SYNOPSIS
20     ##
21 joko 1.3 ## Revision 1.2 2003/02/18 16:02:04 joko
22     ## +- renamed module
23     ##
24 joko 1.2 ## Revision 1.1 2003/02/18 15:34:26 joko
25     ## + initial commit
26     ##
27 joko 1.1 ## -------------------------------------------------------------------------
28    
29    
30     =pod
31    
32     =head1 Preface
33    
34     =head2 hmm.....
35    
36     A Command is a Request.
37     A Task is a Process.
38     A Request is a Command.
39     A Process is a Task.
40     There are just details.
41    
42 joko 1.6
43 joko 1.1 =head2 ahh...
44    
45 joko 1.6 rap means 'Request And Process'.
46     rap is contained in 'wrapped'.
47     dot is the 'Database Of Targets', by default '/etc/rap.xml'. (rename to 'dot.xml'?)
48    
49    
50     CPAN already *has got* all required tools starting an attempt to do this.
51 joko 1.1
52 joko 1.6 Will this work out?
53 joko 1.1 But still, Hmmm......
54     And: lots of work, i believe....
55 joko 1.6 Let's start...
56 joko 1.1
57     Okay:
58 joko 1.4 Look at DesignPattern:: and Data::Mungle::Transform::Deep & Co. (lowlevel stuff)
59 joko 1.1 or OEF::, Data::Storage and Data::Transfer::Sync (highlevel stuff).
60    
61     And then:
62    
63    
64 joko 1.3 =head1 SYNOPSIS
65    
66     my $rap = Data::Rap->new( target => 'sync-core' );
67     $rap->start();
68    
69     print Dumper($rap);
70    
71     print Dumper($rap->get_property('/'));
72    
73     print Dumper($rap->get_property('.'));
74     print Dumper($rap->get_property('global'));
75     print Dumper($rap->get_property('app'));
76     print Dumper($rap->get_property('app.config'));
77     print Dumper($rap->get_property('app.config.preboot'));
78     print Dumper($rap->get_property('app.config.databases.oefcore'));
79    
80    
81 joko 1.1 =head1 Overview
82    
83     =head2 Rap - Request And Process
84    
85 joko 1.6 =head3 Rap's Features
86     - have targets (like make) declared in xml (like ant)
87     - run these targets...
88     - ... from a multitude of possible human interaction devices (HIDs), e.g.
89     - cli (console mode)
90     - gui
91     - web
92     - speech
93     - scribe
94     - ... from a different location (non-local - for remote administration purposes)
95     - the remote wrapper is 'rapd' - the rap-daemon....
96     - rapd can run in command-mode (like apache, sendmail and related)
97     and/or web-service mode (commands are wrapped into request-/response-
98     xml-payload-communication)
99     - rap is self contained on various levels
100     - runtime-layer
101     - pass arguments between targets
102     - core targets are declared in xml (rap-lingo) as well
103     these exist by now: (look at Data/Rap/targets/default.xml)
104     - core.os.win32
105     - core.os.linux
106     - core.rap.mode
107     - core.rap.daemon
108     - declaration-layer
109     - the xml-file in rap-lingo can contain descriptions associated with each target
110     - rap can make report on its guis about these
111     - rap can use this declaration as an api for the rap-daemon 'rapd'
112     - rap itself can run in "global"- or "project"-mode
113     - FIXME: write something about this (by now: read the source, luke.....)
114    
115    
116     =head3 Rap's Future
117     - rapd
118     - rapd can also run in apache mode for non-root purposes
119     - many rapd's can talk to each other - first example application would be:
120     - one rapd is running as apache-mod-perl-handler (non-root)
121     - one rapd is running locally as root
122     - remark: the way to go (by now) is via org.netfrag.glib's DataSource-libraries,
123     which wrap the innards of rpc-communication via xml (XMLRPC) (lingo: php)
124     an example application is caesar.rapweb and (maybe) caesar.ums
125 joko 1.1
126     =head3 Rap's aims are directed to get some of this together
127    
128     - some concepts of make (->targets)
129     - some concepts of ant (->tasks)
130     - some code written while developing a custom application with Perl:
131     - libraries/modules (CPAN proposals)
132     - Data::Storage::Container
133     - Data::Storage
134     - Data::Transfer::Sync
135     - OEF::Component::Task
136     - make "old" shortcut programs like "feed.pl", "tell.pl" and such obsolete
137     - add more targets in order to make "setup.pl" & Co. obsolete as well
138 joko 1.3 - some new concepts (perly):
139     - namespaces
140     - plugins
141     - contexts
142 joko 1.1
143    
144     =head3 It's using these fine modules from CPAN
145    
146     - xml, xpath and such (XML::Parser, XML::XPath)
147     - local os native (background) process execution (IPC::Run)
148     - remote procedure calls with xml payloads: XMLRPC, SOAP and such (RPC::XML, SOAP::Lite)
149     - configuration- and property-data inheritance: Hash::Merge
150    
151     - under the hood:
152     - logging: Log::Dispatch
153     - data-access: DBI & Co., Tangram
154     - data-manipulation: Data::Dumper, Iterate
155     - in other words: all modules already included in some declaration inside 'setup.pl'
156    
157    
158     =head3 Rap does networking
159    
160 joko 1.3 x It's a client. (cli program, standalone)
161     (->Command-Frontends: rap.pl)
162     o It's a server/daemon as well. (cli interacts with daemonized engine via tcp-socket)
163     (->Command-Frontends: rap.pl --remote|--host=<hostname>)
164 joko 1.1
165    
166     =head3 Rap is open for enhancements and/or integration into/with other stuff
167    
168     =head4 Command-Frontends (local and/or remote)
169    
170 joko 1.3 x rap.pl
171 joko 1.1 o Commands can be sent via psh (The Perl Shell) or similar frontends (via rap.pl or Rap.pm)
172     o Commands can be issued from a php-frontend (via RPC using Rap::)
173    
174     =head4 Target-Registry (local and/or remote)
175    
176     x Targets can be defined inside a rap.xml or similar
177     o Targets can be stored in arbitrary data structures (e.g. read from an rdbms or ldap-storage)
178    
179     =head4 Task-Backends (local and/or remote)
180    
181     x Tasks can run as local native processes (attached and/or background)
182     o Tasks can be triggered by issuing RPC-calls to arbitrary multiple hosts
183    
184     =head4 TODO
185     o look at Maven's POM (Project Object Model):
186     - http://jakarta.apache.org/turbine/maven/reference/project-descriptor.html
187     - http://jakarta.apache.org/turbine/maven/images/project-descriptor.gif
188     - http://jakarta.apache.org/turbine/maven/start/integrate.html
189     - http://jakarta.apache.org/turbine/maven/reference/dirlayout.html
190     o integrate with:
191     o POE
192     o PP5E
193     o integrate with pod (for reporting purposes)
194     o look at:
195     btw: "expand": look at scripts@CPAN (System Administration):
196     there is a perl make with perl
197     o refactore child-modules using code from Data::Code only!
198    
199    
200     =cut
201    
202    
203     package Data::Rap;
204    
205     use strict;
206     use warnings;
207    
208     use base qw(
209     DesignPattern::Object
210     DesignPattern::Bridge
211 joko 1.3 DesignPattern::Logger
212     DesignPattern::Exception
213 joko 1.1 );
214    
215    
216     use Data::Dumper;
217 joko 1.3 use Cwd;
218     use File::Spec::Functions qw( splitpath splitdir catpath catdir );
219 joko 1.1
220    
221 joko 1.7 # a package global topic registry
222     our $registry;
223    
224    
225 joko 1.1 sub constructor {
226     my $self = shift;
227 joko 1.3
228     # patch
229     $self->{__rap}->{filename} = $self->{filename};
230     delete $self->{filename};
231    
232     # check
233     if (!$self->{__rap}->{filename}) {
234     $self->{__rap}->{filename} = $self->find_rules();
235     }
236    
237     $self->load([qw( Metadata Engine Command Context Property )]);
238 joko 1.1 #$self->load("Command");
239     #$self->load("Metadata");
240     #$self->load("Engine");
241 jonen 1.5
242 joko 1.1 }
243    
244     sub start {
245     my $self = shift;
246     $self->log("starting", 'info');
247    
248     $self->loadGlobalProperties();
249    
250     #print Dumper($self);
251     if (my $target = $self->{target}) {
252     #$self->{targets}->{$target} = Data::Rap::Target->new( name => $target );
253     $self->log("target: $target", 'info');
254     $self->performTarget($target);
255     } else {
256 joko 1.3 my $meta_raw = $self->getTargetList();
257    
258 joko 1.7 my $maxlength = 0;
259     map {
260     my $len = length($_->{name});
261     $maxlength = $len if $len > $maxlength;
262     } @$meta_raw;
263    
264     my $program = splitpath($0);
265 joko 1.3 foreach my $entry (@$meta_raw) {
266 joko 1.7 my $len = length($entry->{name});
267     #$len = ((1 / ($len / 8)) * 1.9);
268     #$len = ((1 / ($maxlength - $len / 8)) * 1.9);
269     $len = $maxlength - $len + 5;
270     #print "len: $len", "\n";
271     # one line per target
272     print "$program $entry->{name}", " " x $len;
273     print $entry->{description} if $entry->{description};
274     print "\n";
275     # more lines per target
276     #print "$program $entry->{name}", "\n";
277     #print " ", $entry->{description}, "\n" if $entry->{description};
278 joko 1.3 }
279    
280     return;
281    
282     print Dumper($meta_raw);
283     exit;
284    
285 joko 1.1 foreach my $key (keys %{$meta_raw->{target}}) {
286     my $target = $meta_raw->{target}->{$key};
287     print " - rap.pl $key", "\n";
288     my $description = $target->{description};
289     if ($description) {
290     #chomp($description);
291     $description =~ s/^\n+//;
292     $description =~ s/\n+$//;
293     #print "\n" if $description !~ /^\n/;
294     print $description, "\n" if !ref $description;
295     }
296     #print "\n";
297     }
298     }
299    
300     }
301 joko 1.3
302     sub find_rules {
303     my $self = shift;
304    
305 joko 1.6 my $rapfile = 'etc/rap.xml';
306     my $rapfile_found = '';
307    
308     my $basedir = '';
309    
310     # directly from env-var?
311 jonen 1.5 if (my $rapdir = $ENV{RAPDIR}) {
312     $basedir = $rapdir;
313 joko 1.6
314     # relative?
315     } else {
316 jonen 1.5 my $cwd = cwd();
317    
318     (my $volume, my $directory, my $file) = splitpath( $cwd );
319 joko 1.6
320 jonen 1.5 my @dir = splitdir($directory);
321     pop @dir;
322     #pop @dir;
323     $basedir = catpath($volume, catdir(@dir));
324 joko 1.6
325     }
326    
327     #print "basedir: '$basedir'", "\n";
328 jonen 1.5
329 joko 1.6 # check for $basedir/PROJECT
330     if (! -d "$basedir/PROJECT") {
331     $basedir = '';
332     }
333    
334     if ($basedir) {
335     # TODO: review this! handle relative ./etc/rap.xml here!!!
336     $rapfile_found = "$basedir/$rapfile";
337    
338     } else {
339     #if (! -e $rapfile_found) { $rapfile_found = "/$rapfile"; }
340     $rapfile_found = "/$rapfile";
341 jonen 1.5 }
342 joko 1.6
343     #print "rapfile_found: $rapfile_found", "\n";
344    
345    
346     # if rapfile doesn't exists, try to fall back to absolute (global) mode (/etc/rap.xml)
347     #if (! -e $rapfile_found) { $rapfile_found = catpath($volume, "/", $rapfile); }
348     #if (! -e $rapfile_found) { $rapfile_found = "/$rapfile"; }
349    
350     $self->log( "Using rapfile $rapfile_found.", 'info' );
351 joko 1.3
352 joko 1.6 return $rapfile_found;
353 joko 1.3 }
354    
355 joko 1.1
356     1;
357     __END__

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed