jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [branches/] [HotSaNIC-0.5.0-pre6/] [Documentation/] [module-howto/] [howto-common.pm] - Blame information for rev 4

 

Line No. Rev Author Line
11simandlThe "commpn.pm" file in the "platform" directory does all stuff that is common for all operating systems.
2The main use of this file is to tell the settings parser which variables will be used and of what type they are.
3This library must match the following skeleton:
4 
5---------- BEGIN CODE ----------
6package HotSaNICmod::common;
7 
8sub version { return "version string"; }
9sub configure { return %configuration; }
10 
111;
12---------- END CODE ----------
13 
14 
15 
16 
17---------- The "version" funciton ----------
18 
19This function just has to return some identifier string including the library name. If the file is going to be checked into some CVS repository, it is wise to use the CVS keyword "Revision" to automatically include the version number in the version string:
20 
21 
22Example:
23 sub version {
24 ($VERSION = '$Revision: 1.1 $') =~ s/.*(\d+\.\d+).*/$1/;
25 return "common.pm $VERSION";
26 }
27 
28 This will return the sring "common.pm 1.1".
29 
30 
31 
32---------- The "configure" funciton ----------
33 
34The simplest case of this function applies, if the module does not need any configuration at all, then simply anempty array has to be returned:
35 
36sub configure { return (); }
37 
38 
39Another quite simple version can be used, if no further parsing has to be done:
40 
41sub configure { return HotSaNICparser::get_moduleconfig(".",%typehash); }
42 
43 
44The hash %typehash tells the parser how certain variables are to be treated. The hash keys are the names of the items in the settings file, the corrosponding values define the variable type.
45 
46Possible types are:
47 
48 KEY=>"array" the item named "KEY" may appear multiple times and will be an array, which can be referenced as @{$hash{KEY}}
49 KEY=>"bool" the item will be a string, parsed down to a simple "0" or "1", which can be referenced as $hash{KEY}
50 KEY=>"var" the item will be a string, which can be referenced as $hash{KEY}
51 
52If the type is not set, the item will be of the type "array" by default, but the item may be undefined, so make sure in later code to check for existance before referencing this item!
53 
54If items which are defined "var" or "bool" appear multiple times, the LAST matched item applies.
55 
56Default values may be defined in the file ".settings.default" which will be parsed before "settings".
57 
58 
59 
60Example:
61 %MODARGS=HotSaNICparser::get_moduleconfig(".",(FOO=>"array",BAR=>"bool"));
62 
63 This will initialize the array "FOO" and the boolean value "BAR".
64 
65 The boolean type "BAR" will be parsed down to "1" for values of "1", "on", "yes", "true" and to "0" for everything else.
66 The value can be referenced using $MODARGS{BAR}
67 The array "FOO" can later be referenced using @{$MODARGS{FOO}} for example in a loop:
68 
69 foreach $item (@{$MODARGS{FOO}}) { ... }
70 
71 
72 
73 
74The code may for example look like this:
75 
76 
77---------- BEGIN CODE ----------
78package HotSaNICmod::common;
79 
80sub version {
81 ($VERSION = '$Revision: 1.1 $') =~ s/.*(\d+\.\d+).*/$1/;
82 return "common.pm $VERSION";
83 }
84 
85sub configure {
86 %MODARGS=HotSaNICparser::get_moduleconfig(".",(FOO=>"array",BAR=>"bool"));
87 
88 #
89 # apply changes to %MODARGS here
90 # maybe some defaults will have to be set in dependency of some system parameters
91 # global defaults that don't depend on anything else can be defined in the file ".settings.default"
92 #
93 
94 return %MODARGS
95 }
96 
971;
98 
99---------- END CODE ----------
100 

Powered by WebSVN 2.2.1