/
multidispatch-rest-client.pl
43 lines (34 loc) · 1.05 KB
/
multidispatch-rest-client.pl
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
package REST::API {
sub connect {
has ${: login }
:= :required :when ( exists ${: password})
:= :required :when (! exists ${: oauth})
:= not :available :when (exists ${: oauth })
;
has ${: password }
:= :required :when ( exists ${: login})
:= :required :when (! exists ${: oauth})
:= not :available :when (exists ${: oauth })
;
has ${: oauth }
:= not :available :when (exists ${: login })
:= not :available :when (exists ${: password })
;
has ${: authentication }
:= :required
:= not :available
:= :default :when ( exists ${: oauth}) => { REST::API::Authentication::Oauth->new ($oauth) }
:= :default :when (! exists ${: oauth}) => { REST::API::Authentication::Basic->new ($login, $password) }
;
return ...;
}
}
package REST::API::Config {
__PACKAGE__ := :extends => REST::API;
sub connect :extends => &REST::API::connect {
has ${: another_method };
has ${: authentication }
:= :default :when (exists ${: another_method}) => { REST::API::Authentication::Another::Method ($another_method) }
;
}
}