Added proper LGPL statements to all files.
[perl4caml.git] / wrappers / pl_HTML_Form.ml
1 (** Wrapper around Perl [HTML::Form] 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_HTML_Form.ml,v 1.4 2008-03-01 13:02:21 rich Exp $
20   *)
21
22 open Perl
23
24 open Pl_HTTP_Response
25
26 let _ = eval "use HTML::Form"
27
28 class html_form (sv : sv) =
29
30 object (self)
31   method sv = sv
32
33   method attr name =
34     let sv = call_method sv "attr" [sv_of_string name] in
35     (* sv_is_undef doesn't work properly XXX *)
36     if sv_is_undef sv then None else Some (string_of_sv sv)
37   method set_attr name value =
38     call_method_void sv "attr" [sv_of_string name; sv_of_string value]
39
40   (* The following isn't a real method.  The return type of HTML::Form->inputs
41    * isn't documented, but I wanted a list of input names (as strings) anyway.
42    *)
43   method input_names =
44     let inputs = call_method_array sv "inputs" [] in
45     let names = List.map (fun sv -> call_method sv "name" []) inputs in
46     List.map string_of_sv names
47
48 end
49
50 let parse_document html_document base_uri =
51   let svlist = call_class_method_array "HTML::Form" "parse"
52                  [sv_of_string html_document; sv_of_string base_uri] in
53   List.map (new html_form) svlist
54
55 let parse_response (res : http_response) =
56   let svlist = call_class_method_array "HTML::Form" "parse" [res#sv] in
57   List.map (new html_form) svlist