NAME
Kelp::Module::Encoder - Base class for encoder modules
SYNOPSIS
# Writing a new encoder module
package My::Encoder;
use Kelp::Base 'Kelp::Encoder';
use Some::Class;
sub encoder_name { 'something' }
sub build_encoder {
my ($self, $args) = @_;
return Some::Class->new(%$args);
}
sub build {
my ($self, %args) = @_;
$self->SUPER::build(%args);
# rest of module building here if necessary
}
1;
# configuring a special encoder (in app's configuration)
encoders => {
something => {
modified => {
new_argument => 1,
},
},
},
# In application's code
# will croak if encoder was not loaded
# default second argument is 'default' (if not passed)
$self->get_encoder('something')->encode;
$self->get_encoder(something => 'modified')->decode;
DESCRIPTION
This is a base class for encoders which want to be compilant with the new "get_encoder" in Kelp method. Kelp::Module::JSON is one of such modules.
This allows to have all encoders in one easy to reach spot rather than a bunch of unrelated methods attached to the main class. It also allows to configure a couple of named encoders with different config in "encoders" in Kelp::Module::Config configuration of the app.