Added proper LGPL statements to all files.
[perl4caml.git] / wrappers / pl_Net_Google.ml
1 (** Wrapper around Perl [Net::Google] class. *)
2 (*  Copyright (C) 2003 Merjis Ltd.
3
4     This library is free software; you can redistribute it and/or
5     modify it under the terms of the GNU Library General Public
6     License as published by the Free Software Foundation; either
7     version 2 of the License, or (at your option) any later version.
8
9     This library is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12     Library General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this library; see the file COPYING.  If not, write to
16     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17     Boston, MA 02111-1307, USA.
18
19     $Id: pl_Net_Google.ml,v 1.4 2008-03-01 13:02:21 rich Exp $
20   *)
21
22 open Perl
23
24 open Pl_Net_Google_Cache
25 open Pl_Net_Google_Search
26 open Pl_Net_Google_Spelling
27
28 let _ = eval "use Net::Google"
29
30 let may f = function None -> () | Some v -> f v
31
32 class net_google sv =
33
34 object (self)
35
36   method search ?key ?starts_at ?max_results ?lr ?ie ?oe ?safe ?filter () =
37     let args = ref [] in
38     may (fun v ->
39            args := sv_of_string "key" :: sv_of_string v :: !args) key;
40     may (fun v ->
41            args := sv_of_string "starts_at" :: sv_of_int v :: !args) starts_at;
42     may (fun v ->
43            args := sv_of_string "max_results" :: sv_of_int v :: !args)
44       max_results;
45     may (fun v ->
46            args := sv_of_string "lr" :: sv_of_string v :: !args) lr;
47     may (fun v ->
48            args := sv_of_string "ie" :: sv_of_string v :: !args) ie;
49     may (fun v ->
50            args := sv_of_string "oe" :: sv_of_string v :: !args) oe;
51     may (fun v ->
52            args := sv_of_string "safe" :: sv_of_bool v :: !args) safe;
53     may (fun v ->
54            args := sv_of_string "filter" :: sv_of_bool v :: !args) filter;
55     let sv = call_method sv "search" !args in
56     new net_google_search sv
57
58   method spelling ?key ?phrase ?debug () =
59     let args = ref [] in
60     may (fun v ->
61            args := sv_of_string "key" :: sv_of_string v :: !args) key;
62     may (fun v ->
63            args := sv_of_string "phrase" :: sv_of_string v :: !args) phrase;
64     may (fun v ->
65            args := sv_of_string "debug" :: sv_of_int v :: !args) debug;
66     let sv = call_method sv "spelling" !args in
67     new net_google_spelling sv
68
69   method cache ?key ?url ?debug () =
70     let args = ref [] in
71     may (fun v ->
72            args := sv_of_string "key" :: sv_of_string v :: !args) key;
73     may (fun v ->
74            args := sv_of_string "url" :: sv_of_string v :: !args) url;
75     may (fun v ->
76            args := sv_of_string "debug" :: sv_of_int v :: !args) debug;
77     let sv = call_method sv "cache" !args in
78     new net_google_cache sv
79
80 end
81
82 let new_ ?key ?debug () =
83   let args = ref [] in
84   may (fun v ->
85          args := sv_of_string "key" :: sv_of_string v :: !args) key;
86   may (fun v ->
87          args := sv_of_string "debug" :: sv_of_int v :: !args) debug;
88   let sv = call_class_method "Net::Google" "new" !args in
89   new net_google sv