'all'; use JSON; use Carp qw(confess); has 'serializer' => ( is => 'ro', lazy => 1, default => sub { JSON->new() }, ); sub encode { my ($self, $ref) = @_; $self->serializer->encode($ref); } sub decode { my ($self, $data) = @_; $self->serializer->decode($data); }