blob: fd8197116622b4d7648b0bf2e924e53a37cf70ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
Runtime library interfaces for command-line applications
========================================================
See also `environment_variables.txt`
Maybe the aspects of command-line libraries should be some injected objects.
Low level interface:
CommandMain "mycommand"
inject CommandEnvironment env
inject CommandParameters params
inject CommandExitStatus exitstatus
entry main
end
High level interface:
CommandMain "mycommand"
# XXX should it be possible to inject environment variables
# into classes? maybe it's safer/clearer to not allow that?
inject String target = from_environment "TARGET"
inject ?Dir sourcedir = from_commandparam "--srcdir" "-s"
# shorter syntax:
inject
?String target = from_environment "TARGET"
?Dir sourcedir = from_commandparam "--srcdir" "-s"
OutStream stdout = from_stdout
OutStream stderr = from_stderr
CommandExiter exiter = from_system
end
# even shorter syntax, with implied "constructor" names:
# could even only allow one `inject` block to prevent obfuscated code.
inject
?String target environ "TARGET"
?Dir sourcedir cmdparam "--srcdir" "-s"
# using default "constructor"
OutStream stdout
OutStream stderr
CmdExiter exiter
# capabilities can be specified here, too
NativeBinary somebinary with
# scoping rules could make this possible
stderr = stderr
# multi-valued parameters?
filesystem = read "/"
filesystem = writeonly_tempdir
exec = "somebinary" # looked up in PATH
end
end
entry main
CapabilityWrapper cw = new
cw.add "stderr" stderr
cw.add "somebinary" somebinary
SomeOperation op = new cw
op.run sourcedir target
end
Alternative name of the `inject` keyword?
inject
require
demand
environment
env
system
request
params
parameters
parametric
config
configuration
unbound
free
dynamic
hosted
from_host
provided (ok)
need (ok)
needed
giveme (best?)
Handling injection errors
-------------------------
giveme
String name httpparam
File data resource_directory "data"
else
# these are specific implementations of services
MyMissingHttpParam new "this_page"
MyMissingFile new "this_page"
end
|