[Dancer-users] extending the serializer

Mr. Puneet Kishor punk.kish at gmail.com
Tue Jun 7 23:51:43 CEST 2011

I am trying to write a new serializer plugin called `Dancer::Serializer::Tgz` modeled after Data::Dumper, JSON, etc. The idea is that, in conjunction with `Dancer::Plugin::REST` and `Dancer::Serializer::Mutable`, the user would be able to request data in .tgz format on demand like so --

$ curl http://example.com/employees.tgz

Here is my baby code, and it gives me a rather unhelpful "an internal error occurred". What am I doing wrong? Note: in this case, only the serializer (downloading data) makes sense; the deserializer doesn't make any sense.


package Dancer::Serializer::Tgz;

use strict;
use warnings;
use Carp;
use Dancer ':syntax';
use Archive::Tar;
use base 'Dancer::Serializer::Abstract';

# helpers

sub from_tgz {
    my ($string) = @_;
    my $s = Dancer::Serializer::Tgz->new;

sub to_tgz {
    my ($data) = @_;
    my $s = Dancer::Serializer::Tgz->new;

sub serialize {
    my ($self, $entity) = @_;
    my $tar = Archive::Tar->new;
    $tar->add_data('result', to_json($entity));

    my $file = '/tmp/result.tgz';
    $tar->write($file, COMPRESS_GZIP);
    send_file($file, content_type => 'application/gzip', system_path => 1);

sub deserialize {
    my ($self, $content) = @_;
    croak "not yet implemented";

sub content_type {'application/gzip'}


More information about the Dancer-users mailing list