package Local::MooseJson; use strict; use warnings; use Moose; use JSON; use namespace::autoclean; around BUILDARGS => sub { my ($orig, $class, @args) = @_; # Validate @args: 1 element only; JSON text my $json_to_perl = decode_json $args[0]; my $new_hashref = {}; for my $key ($class->meta->get_attribute_list()) { $new_hashref->{$key} = delete $json_to_perl->{$key}; } for my $extra_key (keys %$json_to_perl) { warn "IGNORED! Unknown JSON property: '$extra_key'\n"; } return $class->$orig($new_hashref); }; has body_raw => (is => 'ro', isa => 'Str', required => 1); has entry_id => (is => 'ro', isa => 'Int', required => 1); has icon => (is => 'ro', isa => 'HashRef', required => 1); __PACKAGE__->meta->make_immutable; 1;