Skip to content

Commit

Permalink
bypass LibXML::Node:D raku() built-in method
Browse files Browse the repository at this point in the history
Lessen impact of #95.
  • Loading branch information
dwarring committed Feb 19, 2023
1 parent e48ba34 commit 54c6ee1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
{{$NEXT}}
- Add elementIndex method to LibXML::Element. This is valid
and non-zero after invoking doc.indexElements().
- Lessen impact of #95 (.raku method handing). Override LibXML::Node:D
raku() to call LibXML::Node:U raku().
- Add intermediate domNode() role. This eases class composition
and bypasses the need to nativecast raw nodes, when the type
is known in advance. E.g. getElementsByTagName() is about
25% faster.
- Further optimize LibXML::Node::Set by nativecasting a CArray
as a whole to the container type, rather than casting individual
members.
- Add elementIndex() method to LibXML::Element. After invoking
doc.indexElements(), this returns distinct element numbers,
with the root element having value 1.
- Change xmlElement content() access to return a string. This
is where the element-index (above) is stored.
- Lock-protect error handling.
Expand Down
5 changes: 5 additions & 0 deletions lib/LibXML/Node.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ multi method box(anyNode:D $node, *%c) {
$class.bless: :raw($node.delegate), |%c;
}

multi method raku(::?CLASS:D: $obj?) {
# issue #95
self.WHAT.raku;
}

method getName { self.getNodeName }

#| Gets or sets the node name
Expand Down
20 changes: 20 additions & 0 deletions t/issue#095.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use v6;
use LibXML;
use LibXML::Element;
use Test;
plan 1;

my $html = q:to/XML/;
<body>
<anElem/>
Some text
</body>
XML

my LibXML $parser .= new;
my $doc = $parser.parse(
:string($html),
:!blanks,
);

throws-like { for $doc.root.childNodes -> LibXML::Element $re {} }, X::TypeCheck::Binding::Parameter;

0 comments on commit 54c6ee1

Please sign in to comment.