<commit_before>
# this is called 'Response' in the XML, but we call it 'Result' to not clash
# with 'Response', which is actually 'NZSRSResponse'
package XML::SRS::Result;

use Carp;
use Moose;
use PRANG::Graph;
use XML::SRS::Types;
use XML::SRS::TimeStamp;
use Moose::Util::TypeConstraints;

has_attr 'action' =>
	is => "ro",
	isa => "XML::SRS::ActionEtc",
	required => 1,
	xml_name => "Action",
	;

has_attr 'fe_id' =>
	is => "ro",
	isa => "XML::SRS::Number",
	required => 1,
	xml_name => "FeId",
	;

has_attr 'unique_id' =>
	is => "ro",
	isa => "XML::SRS::Number",
	required => 1,
	xml_name => "FeSeq",
	;

# for identifying a result within a unique transaction
has 'part' =>
	is => "rw",
	isa => "Int",
	;

sub result_id {
	my $self = shift;
	$self->fe_id.",".$self->unique_id
		.($self->part ? ("[".$self->part."]") : "");
}

has_attr 'by_id' =>
	is => "ro",
	isa => "XML::SRS::RegistrarId",
	required => 1,
	xml_name => "OrigRegistrarId",
	;

has_attr 'for_id' =>
	is => "ro",
	isa => "XML::SRS::RegistrarId",
	xml_required => 0,
	xml_name => "RecipientRegistrarId",
	;

has_attr 'client_id' =>
	is => "ro",
	isa => "XML::SRS::UID",
	xml_required => 0,
	xml_name => "TransId",
	;

has_attr 'rows' =>
	is => "ro",
	isa => "XML::SRS::Number",
	xml_required => 0,
	xml_name => "Rows",
	;

has_attr 'has_more_rows' =>
	is => "ro",
	isa => "XML::SRS::Boolean",
	coerce => 1,
	xml_required => 0,
	xml_name => "MoreRowsAvailable",
	;

has_attr 'count' =>
	is => "ro",
	isa => "XML::SRS::Number",
	xml_required => 0,
	xml_name => "Count",
	;

subtype 'XML::SRS::timeStampType'
	=> as "XML::SRS::TimeStamp",
	;

coerce "XML::SRS::timeStampType"
	=> from TimestampTZ
	=> via {
	XML::SRS::TimeStamp->new(timestamptz => $_);
	};
	
coerce "XML::SRS::timeStampType"
    => from 'Str'
    => via {
    XML::SRS::TimeStamp->new(timestamptz => $_);
    };

has_element 'server_time' =>
	is => "ro",
	isa => "XML::SRS::timeStampType",
	coerce => 1,
	xml_nodeName => "FeTimeStamp",
	required => 1,
	;

use MooseX::Timestamp;
use MooseX::TimestampTZ;



# this is for GetMessages responses, so let's call it messages
has_element 'messages' =>
	is => "ro",
	isa => "ArrayRef[XML::SRS::Result]",
	xml_nodeName => "Response",
	xml_min => 0,
	;
	
role_type 'XML::SRS::ActionResponse';

has_element 'responses' =>
	is => "ro",
	isa => "ArrayRef[XML::SRS::ActionResponse]",
	xml_required => 0,
	lazy => 1,
	default => sub {
	my $self = shift;
	($self->has_response and defined $self->response)
		? [ $self->response ] : [];
	},
	;

has 'response' =>
	is => "ro",
	isa => "Maybe[XML::SRS::ActionResponse]",
	predicate => "has_response",
	lazy => 1,
	default => sub {
	my $self = shift;
	my $rs_a = $self->responses;
	if ( $rs_a and @$rs_a ) {
		if ( @$rs_a > 1 ) {
			confess "result has multiple responses";
		}
		else {
			$rs_a->[0];
		}
	}
	else {
		undef;
	}
	},
	;

sub is_error {
    my $self = shift;
    
    my $responses = $self->responses;
    
    return $responses->[0]->isa('XML::SRS::Error');   
}<commit_msg>wr217284: handle a result with no responses<commit_after>
# this is called 'Response' in the XML, but we call it 'Result' to not clash
# with 'Response', which is actually 'NZSRSResponse'
package XML::SRS::Result;

use Carp;
use Moose;
use PRANG::Graph;
use XML::SRS::Types;
use XML::SRS::TimeStamp;
use Moose::Util::TypeConstraints;

has_attr 'action' =>
	is => "ro",
	isa => "XML::SRS::ActionEtc",
	required => 1,
	xml_name => "Action",
	;

has_attr 'fe_id' =>
	is => "ro",
	isa => "XML::SRS::Number",
	required => 1,
	xml_name => "FeId",
	;

has_attr 'unique_id' =>
	is => "ro",
	isa => "XML::SRS::Number",
	required => 1,
	xml_name => "FeSeq",
	;

# for identifying a result within a unique transaction
has 'part' =>
	is => "rw",
	isa => "Int",
	;

sub result_id {
	my $self = shift;
	$self->fe_id.",".$self->unique_id
		.($self->part ? ("[".$self->part."]") : "");
}

has_attr 'by_id' =>
	is => "ro",
	isa => "XML::SRS::RegistrarId",
	required => 1,
	xml_name => "OrigRegistrarId",
	;

has_attr 'for_id' =>
	is => "ro",
	isa => "XML::SRS::RegistrarId",
	xml_required => 0,
	xml_name => "RecipientRegistrarId",
	;

has_attr 'client_id' =>
	is => "ro",
	isa => "XML::SRS::UID",
	xml_required => 0,
	xml_name => "TransId",
	;

has_attr 'rows' =>
	is => "ro",
	isa => "XML::SRS::Number",
	xml_required => 0,
	xml_name => "Rows",
	;

has_attr 'has_more_rows' =>
	is => "ro",
	isa => "XML::SRS::Boolean",
	coerce => 1,
	xml_required => 0,
	xml_name => "MoreRowsAvailable",
	;

has_attr 'count' =>
	is => "ro",
	isa => "XML::SRS::Number",
	xml_required => 0,
	xml_name => "Count",
	;

subtype 'XML::SRS::timeStampType'
	=> as "XML::SRS::TimeStamp",
	;

coerce "XML::SRS::timeStampType"
	=> from TimestampTZ
	=> via {
	XML::SRS::TimeStamp->new(timestamptz => $_);
	};
	
coerce "XML::SRS::timeStampType"
    => from 'Str'
    => via {
    XML::SRS::TimeStamp->new(timestamptz => $_);
    };

has_element 'server_time' =>
	is => "ro",
	isa => "XML::SRS::timeStampType",
	coerce => 1,
	xml_nodeName => "FeTimeStamp",
	required => 1,
	;

use MooseX::Timestamp;
use MooseX::TimestampTZ;



# this is for GetMessages responses, so let's call it messages
has_element 'messages' =>
	is => "ro",
	isa => "ArrayRef[XML::SRS::Result]",
	xml_nodeName => "Response",
	xml_min => 0,
	;
	
role_type 'XML::SRS::ActionResponse';

has_element 'responses' =>
	is => "ro",
	isa => "ArrayRef[XML::SRS::ActionResponse]",
	xml_required => 0,
	lazy => 1,
	default => sub {
	my $self = shift;
	($self->has_response and defined $self->response)
		? [ $self->response ] : [];
	},
	;

has 'response' =>
	is => "ro",
	isa => "Maybe[XML::SRS::ActionResponse]",
	predicate => "has_response",
	lazy => 1,
	default => sub {
	my $self = shift;
	my $rs_a = $self->responses;
	if ( $rs_a and @$rs_a ) {
		if ( @$rs_a > 1 ) {
			confess "result has multiple responses";
		}
		else {
			$rs_a->[0];
		}
	}
	else {
		undef;
	}
	},
	;

sub is_error {
    my $self = shift;
    
    my $responses = $self->responses;
    
    return 0 unless @$responses;
    
    return $responses->[0]->isa('XML::SRS::Error');   
}
{'fraction_non_alphanumeric': 0.21000658327847269, 'fraction_numerical': 0.007406188281764319, 'mean_word_length': 3.9648692810457518, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 191, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 36}, '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': '3060404', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2524, 'n_words': 546}