Added ocamldoc, and fixed bugs.
[perl4caml.git] / wrappers / pl_HTML_Element.ml
index 6430985..a460416 100644 (file)
@@ -1,10 +1,14 @@
-(* Wrapper around Perl HTML::Element class.
- * Copyright (C) 2003 Merjis Ltd.
- * $Id: pl_HTML_Element.ml,v 1.1 2003-10-12 17:33:15 rich Exp $
- *)
+(** Wrapper around Perl [HTML::Element] class.
+  *
+  * Copyright (C) 2003 Merjis Ltd.
+  *
+  * $Id: pl_HTML_Element.ml,v 1.4 2003-10-16 13:41:07 rich Exp $
+  *)
 
 open Perl
 
+let _ = eval "use HTML::Element"
+
 type 'a content_t = Element of 'a | String of string
 
 class html_element sv =
@@ -43,10 +47,17 @@ object (self)
     let svlist = call_method_array sv "content_list" [] in
     List.map
       (fun c ->
-        match sv_type c with
-            SVt_PV -> String (string_of_sv c)
-          | SVt_RV -> Element (new html_element (deref c))
-          | _ -> failwith "HTML::Element content_type: unknown type"
+        (* Not very satisfactory, but sv_type fails to discern the type
+         * for some reason. XXX
+         *)
+        let str = string_of_sv c in
+        let marker = "HTML::Element=HASH(" in
+        let marker_len = String.length marker in
+        if String.length str > marker_len &&
+          String.sub str 0 marker_len = marker then
+            Element (new html_element c)
+        else
+          String (string_of_sv c)
       ) svlist
   method all_attr =
     let svlist = call_method_array sv "all_attr" [] in