I want to change app_url.
I did it as follows:
package Post;
use Kelp::Base 'Kelp';
use utf8;
sub before_dispatch {
# overriding this method disables access logs
}
sub build {
my $self = shift;
$self->config_hash->{app_url}='https://perl-kelp.sys5.co';
It seems to work. Is this a good way?
Changing the app_url in a Perl Kelp application as you described is valid but not ideal... A more standard approach involves using configuration files or environment variables. To use configuration files, create a file like conf/config.pl and specify your settings, including the app_url. For example:
{
app_url => 'https://perl-kelp.sys5.co',
# other configurations...
}
Then, modify your Post module to load this configuration:
package Post;
use Kelp::Base 'Kelp';
sub build {
my $self = shift;
my $app_url = $self->config('app_url');
# use $app_url as needed
}
1;
Alternatively, you can use environment variables to manage configurations. Set an environment variable for app_url:
export APP_URL='https://perl-kelp.sys5.co'
Modify your Post module to read this variable:
package Post;
use Kelp::Base 'Kelp';
sub build {
my $self = shift;
my $app_url = $ENV{'APP_URL'} || 'default_value';
# use $app_url as needed again
}
1;
Using configuration files or environment variables ensures better maintainability and flexibility for your Kelp application. All of this is generally considered a good practice for larger projects and organizations.