-
Notifications
You must be signed in to change notification settings - Fork 1
/
TODO
71 lines (44 loc) · 1.42 KB
/
TODO
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
- use Sub::Name to set anonymous functions names
# a few shots at getting a usable syntax for
# a source filter variant of the contract declaration
#-------------------------------------
#
# simple way
#
#-------------------------------------
package MyPkg;
use Sub::Contract;
contract('foo',
in => [ &valid1, &valid2, a => &valid3, b => &valid4 ],
out => [ &valid1, a => &valid3 ],
cache => SIZE,
);
# contract_in/out dies if foo already declared previously
sub foo {
return @aa;
}
# since we have encountered a contract declaration
# for both in and out arguments for foo,
# source filter replaces foo by:
sub foo {
Sub::Contract::validate_MyPkg_foo_in(@_);
return Sub::Contract::validate_MyPkg_foo_out @aa;
}
# in Sub::Contract:
sub UNIVERSAL {
# called when Sub::Contract::validate_... called from somewhere
# if ... validator does not exist, create it!
}
# EVAL:
# - quite efficient: call validate_... only when a contract exists.
# - easy to enable/disable contracts during runtime by putting
# a 'return if disabled' in beginning of validate_...
# - problem: no support for variable lenght argument lists in contract_in/out
# - a bit hard to parse all perl variants of sub { and return declarations (but
# not too hard)
#-------------------------------------
#
# the function prototype way
#
#-------------------------------------
sub foo :contract(in => {}, out => {})