refactor serialization config
[catagits/Catalyst-Action-REST.git] / lib / Catalyst / ControllerRole / SerializeConfig.pm
1 package Catalyst::ControllerRole::SerializeConfig;
2 use Moose::Role;
3 use namespace::clean -except => 'meta';
4
5 my @KEYS = qw(map content_type_stash_key default);
6
7 has serialize_config => (
8   is         => 'ro',
9   isa        => 'HashRef',
10   init_arg   => undef,
11   lazy_build => 1,
12 );
13
14 sub _build_serialize_config {
15   my $self = shift;
16   my $c = $self->_application;
17   my $config;
18   if ( exists $self->{serialize} ) {
19     $c->log->info("Using deprecated configuration for Catalyst::Action::REST!");
20     $c->log->info("Please see perldoc Catalyst::Action::REST for the update guide");
21     $config = $self->{serialize};
22     # if they're using the deprecated config, they may be expecting a
23     # default mapping too.
24     $config->{map} ||= $self->{map};
25   } else {
26     # do not store a reference to itself in the controller
27     $config = {
28       map {; $_ => $self->{$_} } @KEYS
29     };
30   }
31   return $config;
32 };
33
34 1;