So I have the following routine:
method getAttributeNode($a) {
my $ret = domGetAttrNode(self, $a);
#my $retVal = $ret.clone;
#xmlFree($ret);
# cw: Returns CStruct allocated from libxml2!
return $ret;
}
sub domGetAttrNode(xmlNode $n, Str $a) is export {
my $name = $a.subst(/\s/, '');
return unless $name;
my $ret;
unless $ret := nativecast(
xmlAttr, xmlHasNsProp($n, $a, Str)
) {
my ($prefix, $localname) = $a.split(':');
if !$localname {
$localname = $prefix;
$prefix = Nil;
}
if $localname {
my $ns = xmlSearchNs($n.doc, $n, $prefix);
if $ns {
$ret := nativecast(
xmlAttr, xmlHasNsProp($n, $localname, $ns.href)
);
}
}
}
return if $ret && $ret.type != XML_ATTRIBUTE_NODE;
return $ret;
}
And the following code:
my $attr = $elem.getAttributeNode($attname1);
# TEST
ok $attr, 'can retrieve attribute node';
# TEST
is $attr.name, $attname1, 'attribute name is properly set';
# TEST
is $attr.value, $attvalue1, 'attribute value is properly set';
$elem.setAttribute( $attname1, $attvalue2 );
# TEST -14
is $elem.getAttribute($attname1), $attvalue2, 'retrieved correct attribute value via element';
# TEST
is $attr.value, $attvalue2, 'new value successfully propagated to attribute';
Which produces the following output:
ok 10 - can retrieve attribute node
ok 11 - attribute name is properly set
ok 12 - attribute value is properly set
ok 13 - retrieved correct attribute value via element
not ok 14 - new value successfully propagated to attribute
But if the first block of code properly retrieves the pointer from libxml2, why isn't the change being reflected in the $attr object?
I believe that NC caches attribute values like
$attr.value
. To refresh just callrefresh($attr)
. See https://github.com/rakudo/rakudo/blob/nom/lib/NativeCall.pm6#L381 for reference.If that helps here, we need to consider a properly working mechanism.