<commit_before>package Eixo::Rest::ApiFakeServer;

use strict;
use Eixo::Base::Clase;

has(

	listeners=>{},

	cgi=>undef,

);

sub initialize{
	my ($self, %args) = @_;
	
	# we treat special routes, ie. with placeholders...

	my $routes = [];	

	foreach my $r (keys(%{$args{listeners}})){

		if($r =~ /\:/){

			my $n = $r;

			while($r =~ /\:(\w+)/g){

				$n =~ s/\:$1/\[\^\/\]\+/;
			}

			$n .= '$';

			$n = qr/$n/;

			push @$routes, {

				tester=>sub {
			
					$_[0] =~ /$n/;
				
				},

				route=>$r
			}

		}
		else{
			unshift @$routes, {

				tester=>sub {

					$_[0] eq $r;
				},

				route=>$r
			}
		}

	}

	$self->{routes} = $routes;

	foreach(values(%{$self->{listeners}})){

		$_->{type} = "GET" unless($_->{type});
	}

	$self;
}

sub start{
	my ($self, $port) = @_;

	return Eixo::Rest::ApiFakeServerProcess::start_server(

		$port,

		$self
	);

}

sub process{
	my ($self, $cgi) = @_;

	$self->cgi($cgi);

	my $listener = $self->__getListener($cgi) || $self->__defaultListener;

	$self->__send(

		$listener
	);

}

sub __getListener{
	my ($self, $cgi) = @_;

	my $method;

	foreach(@{$self->{routes}}){

		if($_->{tester}->($cgi->path_info)){
			$method = $self->{listeners}->{$_->{route}};
			last;
		}
	}

	return $method if($method && lc($method->{type}) eq lc($cgi->request_method));
}

sub __defaultListener{
	{}
}

sub __send{
	my ($self, $response) = @_;

	($response->{header}) ? $response->{header}->($self) : $self->__header;

	($response->{body}) ? $response->{body}->($self) : $self->__body;
<commit_msg>Small changes for better mockup test<commit_after>package Eixo::Rest::ApiFakeServer;

use strict;
use Eixo::Base::Clase;

has(

	listeners=>{},

	cgi=>undef,

);

sub initialize{
	my ($self, %args) = @_;
	
	# we treat special routes, ie. with placeholders...

	my $routes = [];	

	foreach my $r (keys(%{$args{listeners}})){

		if($r =~ /\:/){

			my $n = $r;

			while($r =~ /\:(\w+)/g){

				$n =~ s/\:$1/\[\^\/\]\+/;
			}

			$n .= '$';

			$n = qr/$n/;

			push @$routes, {

				tester=>sub {
			
					$_[0] =~ /$n/;
				
				},

				route=>$r
			}

		}
		else{
			unshift @$routes, {

				tester=>sub {

					$_[0] eq $r;
				},

				route=>$r
			}
		}

	}

	$self->{routes} = $routes;

	foreach(values(%{$self->{listeners}})){

		$_->{type} = "GET" unless($_->{type});
	}

	$self;
}

sub start{
	my ($self, $port) = @_;

	return Eixo::Rest::ApiFakeServerProcess::start_server(

		$port,

		$self
	);

}

sub process{
	my ($self, $cgi) = @_;

	$self->cgi($cgi);

	my $listener = $self->__getListener($cgi) || $self->__defaultListener;

	$self->__send(

		$listener
	);

}

sub __getListener{
	my ($self, $cgi) = @_;

	foreach my $r (@{$self->{routes}}){

		if($r->{tester}->($cgi->path_info)){

			my $method = $self->{listeners}->{$r->{route}};

			return $method if($method->{type} eq '*');

			return $method if(lc($method->{type}) eq lc($cgi->request_method));
		}
	}

}

sub __defaultListener{
	{}
}

sub __send{
	my ($self, $response) = @_;

	($response->{header}) ? $response->{header}->($self) : $self->__header;

	($response->{body}) ? $response->{body}->($self) : $self->__body;

{'fraction_non_alphanumeric': 0.2573341836734694, 'fraction_numerical': 0.001913265306122449, 'mean_word_length': 2.9017412935323383, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 66, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '4867492', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1308, 'n_words': 231}