rename func

This commit is contained in:
Ougi 2023-11-10 15:17:18 +03:00
parent c1eee1f1d0
commit 38342df5cf

View file

@ -11,18 +11,12 @@ our $VERSION = '0.1';
my $regex_for_email = my $regex_for_email =
qr((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])); qr((?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\]));
sub valid_param { sub validate_address {
my $address = shift; my $address = shift;
if ( $address =~ $regex_for_email ) { if ( $address =~ $regex_for_email ) {
return { return 1
flag => 0,
address => $1
};
} }
return { return (0,'Invalid message')
flag => 1,
address => "Error Address"
};
} }
get '/' => sub { get '/' => sub {
@ -30,20 +24,25 @@ get '/' => sub {
}; };
post '/logs' => sub { post '/logs' => sub {
my %params = %{ valid_param( body_parameters->get('address') ) }; my $address = body_parameters->get('address');
my ($is_valid_address,$validation_message) = validate_address($address);
my %result;
if ($is_valid_address){
my $dbh = DB->new(); my $dbh = DB->new();
$dbh->connect(); $dbh->connect();
my %res_get_rows = %{ $dbh->get_rows( $params{address} ) }; %result = %{ $dbh->get_rows( $address ) };
}
template 'logs' => { template 'logs' => {
title => $params{flag}, title => $address,
err => $params{address}, err => $validation_message,
alert => $res_get_rows{alert}, alert => $result{alert} || [],
rows => $res_get_rows{table}, rows => $result{table} || [],
get_address => uri_for('/'), get_address => uri_for('/'),
}; };
}; };
true; true;