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 =
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;
if ( $address =~ $regex_for_email ) {
return {
flag => 0,
address => $1
};
return 1
}
return {
flag => 1,
address => "Error Address"
};
return (0,'Invalid message')
}
get '/' => sub {
@ -30,20 +24,25 @@ get '/' => 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();
$dbh->connect();
my %res_get_rows = %{ $dbh->get_rows( $params{address} ) };
%result = %{ $dbh->get_rows( $address ) };
}
template 'logs' => {
title => $params{flag},
err => $params{address},
alert => $res_get_rows{alert},
rows => $res_get_rows{table},
title => $address,
err => $validation_message,
alert => $result{alert} || [],
rows => $result{table} || [],
get_address => uri_for('/'),
};
};
true;