I have a solution for this currently but it may not be the most versatile code. I know there is a way to use templates with placeholders for variables instead of putting the actual runtime parameters into the error message. Apologies if what I'm asking is unclear. I don't have a whole lot of knowledge on how to use templates.
use constant {
#list will contain more errors
ERROR_SW => {
errorCode => 727,
message => sub{"Not able to ping switch $switch_ip in $timeout seconds"},
fatal => 1,
web_page => 'http://www.errorsolution.com/727',
}
};
sub error_post {
my ($error) = @_;
print($error->{message}());
}
error_post(ERROR_SW);
I am trying to design it so that I can use placeholders for $switch_ip and $timeout instead of having to declare the message as a subroutine reference. Like below
use constant {
#list will contain more errors
ERROR_SW => {
errorCode => 727,
message => "Not able to ping switch **{{switch_ip}}** in **{{timeout}}** seconds",
fatal => 1,
web_page => 'http://www.errorsolution.com/727',
}
};
sub error_post {
my ($error) = @_;
print($error->{message});
}
error_post(ERROR_SW);
They also appear in code like so:
%%error%%
I'm not sure how to create the template which will handle the parameters. Again Apologies for being vague or not explaining this well.