summaryrefslogtreecommitdiff
path: root/lib/XML/LibXML.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/XML/LibXML.pm')
-rw-r--r--lib/XML/LibXML.pm50
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/XML/LibXML.pm b/lib/XML/LibXML.pm
new file mode 100644
index 0000000..a9c8fbb
--- /dev/null
+++ b/lib/XML/LibXML.pm
@@ -0,0 +1,50 @@
+# -*- mode: perl6 -*-
+use NativeCall;
+
+class XML::LibXML::Node is repr('CStruct') {
+ sub xmlFreeNode(XML::LibXML::Node $doc) is native('libxml2') {*}
+ submethod DESTROY { xmlFreeNode(self) }
+
+ has Pointer $!_private;
+ has int $.xmlElementType;
+ has Str $.name;
+ # etc etc, don't try to create this
+}
+
+class XML::LibXML::Document is repr('CPointer') {
+ sub xmlFreeDoc(XML::LibXML::Document $doc) is native('libxml2') {*}
+ submethod DESTROY { xmlFreeDoc(self) }
+
+ sub xmlDocGetRootElement(XML::LibXML::Document $doc)
+ returns XML::LibXML::Node is native('libxml2') {*}
+ method rootElement() {
+ return xmlDocGetRootElement(self);
+ }
+}
+
+class XML::LibXML::Context is repr('CStruct') {
+ sub xmlFreeParserCtxt(XML::LibXML::Context $ctxt) is native('libxml2') {*}
+ submethod DESTROY { xmlFreeParserCtxt(self) }
+
+ sub xmlParseDocument(XML::LibXML::Context $ctxt) is native('libxml2') {*}
+ method parse() { xmlParseDocument(self) }
+
+ has Pointer $!sax; # currently unused
+ has Pointer $!userData; # useless?
+ has XML::LibXML::Document $.myDoc;
+ # etc etc, don't try to create this
+}
+
+class XML::LibXML {
+ sub xmlCreateMemoryParserCtxt(Blob $docbuf, int $len) returns XML::LibXML::Context is native('libxml2') {*}
+
+ method parse(Str $docstring) {
+ my Blob $docbuf = $docstring.encode('utf8');
+ my $ctxt = xmlCreateMemoryParserCtxt(
+ $docbuf,
+ $docbuf.bytes,
+ );
+ $ctxt.parse();
+ return $ctxt.myDoc;
+ }
+}