<commit_before>
package PRANG::Graph::Element;

use 5.010;
use Moose;
use MooseX::Method::Signatures;
use Moose::Util::TypeConstraints;
use XML::LibXML;

BEGIN {
	class_type "XML::LibXML::Node";
	class_type "XML::LibXML::Element";
}

has 'xmlns' =>
	is => "ro",
	isa => "Str",
	predicate => "has_xmlns",
	;

has 'nodeName' =>
	is => "ro",
	isa => "Str",
	required => 1,
	;

has 'nodeClass' =>
	is => "ro",
	isa => "Str",
	predicate => "has_nodeClass",
	;

has 'nodeName_attr' =>
	is => "rw",
	isa => "Str",
	predicate => "has_nodeName_attr",
	;

has 'attrName' =>
	is => "ro",
	isa => "Str",
	required => 1,
	;

has 'contents' =>
	is => "rw",
	isa => "PRANG::Graph::Node",
	predicate => "has_contents",
	;

method node_ok( XML::LibXML::Node $node, PRANG::Graph::Context $ctx ) {
	return unless $node->nodeType == XML_ELEMENT_NODE;
	if ( ($node->prefix||"") ne ($ctx->prefix||"") ) {
		my $got_xmlns = ($ctx->xsi->{$node->prefix||""}||"");
		my $wanted_xmlns = ($self->xmlns||"");
		if ( $wanted_xmlns ne "*" and
			     $got_xmlns ne $wanted_xmlns ) {
			$ctx->exception("invalid XML namespace", $node, 1);
		}
	}
	# this is bad for processContents=skip + namespace="##other"
	my $ret_nodeName = $self->nodeName eq "*" ?
		$node->localname : "";
	if ( !$ret_nodeName and $node->localname ne $self->nodeName ) {
		return;
	}
	else {
		return $ret_nodeName;
	}
}

method accept( XML::LibXML::Node $node, PRANG::Graph::Context $ctx ) {
	my $ret_nodeName;
	if ( !defined ($ret_nodeName = $self->node_ok($node, $ctx)) ) {
		$ctx->exception(
		"invalid element; expected '".$self->nodeName."'",
			$node, 1,
		       );
	}
	undef($ret_nodeName) if !length($ret_nodeName);
	if ( $self->has_nodeClass ) {
		# general nested XML support
		my $marshaller = $ctx->base->get($self->nodeClass);
		my $value = ( $marshaller ? $marshaller->marshall_in_element(
			$node,
			$ctx,
		       )
				      : $node );
		$ctx->element_ok(1);
		return ($self->attrName => $value, $ret_nodeName);
	}
	else {
		# XML data types
		my $type = $self->has_contents ?
			"XML data" : "presence-only";
		if ($node->hasAttributes) {
			$ctx->exception(
			"Superfluous attributes on $type node",
				$node);
		}
		if ( $self->has_contents ) {
			# simple types, eg Int, Str
			my (@childNodes) = grep {
                		!($_->isa("XML::LibXML::Comment") or<commit_msg>PRANG::Graph::Element: don't raise an exception in node_ok<commit_after>
package PRANG::Graph::Element;

use 5.010;
use Moose;
use MooseX::Method::Signatures;
use Moose::Util::TypeConstraints;
use XML::LibXML;

BEGIN {
	class_type "XML::LibXML::Node";
	class_type "XML::LibXML::Element";
}

has 'xmlns' =>
	is => "ro",
	isa => "Str",
	predicate => "has_xmlns",
	;

has 'nodeName' =>
	is => "ro",
	isa => "Str",
	required => 1,
	;

has 'nodeClass' =>
	is => "ro",
	isa => "Str",
	predicate => "has_nodeClass",
	;

has 'nodeName_attr' =>
	is => "rw",
	isa => "Str",
	predicate => "has_nodeName_attr",
	;

has 'attrName' =>
	is => "ro",
	isa => "Str",
	required => 1,
	;

has 'contents' =>
	is => "rw",
	isa => "PRANG::Graph::Node",
	predicate => "has_contents",
	;

method node_ok( XML::LibXML::Node $node, PRANG::Graph::Context $ctx ) {
	return unless $node->nodeType == XML_ELEMENT_NODE;
	if ( ($node->prefix||"") ne ($ctx->prefix||"") ) {
		my $got_xmlns = ($ctx->xsi->{$node->prefix||""}||"");
		my $wanted_xmlns = ($self->xmlns||"");
		if ( $wanted_xmlns ne "*" and
			     $got_xmlns ne $wanted_xmlns ) {
			return;
		}
	}
	# this is bad for processContents=skip + namespace="##other"
	my $ret_nodeName = $self->nodeName eq "*" ?
		$node->localname : "";
	if ( !$ret_nodeName and $node->localname ne $self->nodeName ) {
		return;
	}
	else {
		return $ret_nodeName;
	}
}

method accept( XML::LibXML::Node $node, PRANG::Graph::Context $ctx ) {
	my $ret_nodeName;
	if ( !defined ($ret_nodeName = $self->node_ok($node, $ctx)) ) {

		# ok, not right, so figure out what we did want, in
		# the context of the incoming document.
		my $wanted_xmlns = ($self->xmlns||"");
		my $wanted_prefix = $ctx->get_prefix($wanted_xmlns);

		my $nodeName = $self->nodeName;
		if ( $wanted_prefix ne "" ) {
			$nodeName = "$wanted_prefix:$nodeName";
			if ( $ctx->prefix_new($wanted_prefix) ) {
				$nodeName .= " xmlns:$wanted_prefix="
					."\"$wanted_xmlns\"";
			}
		}
		$ctx->exception(
		"invalid element; expected '$nodeName'",
			$node, 1,
		       );
	}
	undef($ret_nodeName) if !length($ret_nodeName);
	if ( $self->has_nodeClass ) {
		# general nested XML support
		my $marshaller = $ctx->base->get($self->nodeClass);
		my $value = ( $marshaller ? $marshaller->marshall_in_element(
			$node,
			$ctx,
		       )
				      : $node );
		$ctx->element_ok(1);
		return ($self->attrName => $value, $ret_nodeName);
	}
	else {
		# XML data types
		my $type = $self->has_contents ?
			"XML data" : "presence-only";
		if ($node->hasAttributes) {
			$ctx->exception(
			"Superfluous attributes on $type node",
				$node);
		}
		if ( $self->has_contents ) {
			# simple types, eg Int, Str
			my (@childNodes) = grep {
                		!($_->isa("XML::LibXML::Comment") or
{'fraction_non_alphanumeric': 0.2009428403064231, 'fraction_numerical': 0.003339226085248478, 'mean_word_length': 3.7104532839962996, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 21}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6856629', 'n_tokens_mistral': 2110, 'n_tokens_neox': 1952, 'n_words': 425}