Version 0.3.4 for release.
[perl4caml.git] / wrappers / pl_Net_Google.ml
1 (* Wrapper around Perl Net::Google class.
2  * Copyright (C) 2003 Merjis Ltd.
3  * $Id: pl_Net_Google.ml,v 1.2 2003-10-15 16:51:12 rich Exp $
4  *)
5
6 open Perl
7
8 open Pl_Net_Google_Cache
9 open Pl_Net_Google_Search
10 open Pl_Net_Google_Spelling
11
12 let _ = eval "use Net::Google"
13
14 let may f = function None -> () | Some v -> f v
15
16 class net_google sv =
17
18 object (self)
19
20   method search ?key ?starts_at ?max_results ?lr ?ie ?oe ?safe ?filter () =
21     let args = ref [] in
22     may (fun v ->
23            args := sv_of_string "key" :: sv_of_string v :: !args) key;
24     may (fun v ->
25            args := sv_of_string "starts_at" :: sv_of_int v :: !args) starts_at;
26     may (fun v ->
27            args := sv_of_string "max_results" :: sv_of_int v :: !args)
28       max_results;
29     may (fun v ->
30            args := sv_of_string "lr" :: sv_of_string v :: !args) lr;
31     may (fun v ->
32            args := sv_of_string "ie" :: sv_of_string v :: !args) ie;
33     may (fun v ->
34            args := sv_of_string "oe" :: sv_of_string v :: !args) oe;
35     may (fun v ->
36            args := sv_of_string "safe" :: sv_of_bool v :: !args) safe;
37     may (fun v ->
38            args := sv_of_string "filter" :: sv_of_bool v :: !args) filter;
39     let sv = call_method sv "search" !args in
40     new net_google_search sv
41
42   method spelling ?key ?phrase ?debug () =
43     let args = ref [] in
44     may (fun v ->
45            args := sv_of_string "key" :: sv_of_string v :: !args) key;
46     may (fun v ->
47            args := sv_of_string "phrase" :: sv_of_string v :: !args) phrase;
48     may (fun v ->
49            args := sv_of_string "debug" :: sv_of_int v :: !args) debug;
50     let sv = call_method sv "spelling" !args in
51     new net_google_spelling sv
52
53   method cache ?key ?url ?debug () =
54     let args = ref [] in
55     may (fun v ->
56            args := sv_of_string "key" :: sv_of_string v :: !args) key;
57     may (fun v ->
58            args := sv_of_string "url" :: sv_of_string v :: !args) url;
59     may (fun v ->
60            args := sv_of_string "debug" :: sv_of_int v :: !args) debug;
61     let sv = call_method sv "cache" !args in
62     new net_google_cache sv
63
64 end
65
66 let new_ ?key ?debug () =
67   let args = ref [] in
68   may (fun v ->
69          args := sv_of_string "key" :: sv_of_string v :: !args) key;
70   may (fun v ->
71          args := sv_of_string "debug" :: sv_of_int v :: !args) debug;
72   let sv = call_class_method "Net::Google" "new" !args in
73   new net_google sv