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