catalyst  

[Catalyst] Catalyst::Action::SerializeBase::_load_content_plugins default behavior

Dave Goehrig
Mon, 08 Feb 2010 06:54:37 -0800

Dear List,

I recently upgraded a project I'm working on to track some of the latest
changes in Catalyst::Action::REST, and noticed that in our application's
case the change to the 'serialize' config parameter altered the default
behavior of the application.  The previous behavior had a config that
looked like:

__PACKAGE__->config(
    serialize => {
        default => 'application/json',
        map => {
            'application/json' => 'JSONP',
            'text/x-php-serialization' => ['Data::Serializer',
'PHP::Serialization' ],
        }
    }
);

Would and still does, result in the application returning
'application/json' by default, because on line 182 of
Catatlyst::Action::SerializeBase

$config = $controller->{'serialize'}

Overrides the default map!

However, if you use the new config style:

__PACKAGE__->config(
   default => 'application/json',
   map => {
      'application/json' => 'JSONP',
      'text/x-php-serialization' => ['Data::Serializer',
'PHP::Serialization' ],
   }
);

The map entries are then appended to the default $config->map, and net
result is these additional mappings are never seen.  This is because a
silly AJAX requests which never specified a content-type now use the
"default" behavior based on the browser's Accept-Encoding, which is
ALWAYS 'text/html'!

As a result, instead of returning a 'default' => 'application/json', it
quite rightly returns a default => 'text/html' which serializes based on
Catalyst::Action::YAML::HTML

Based on the documentation, both behaviors are correct, but it seems to
me that if I specify a local mapping that it should override the default
map as it did in the old behavior.  Was this change a bug or a design
decision?

- Dave Goehrig

dgoeh...@synacor.com    

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/