Role::HasPayload::Merged - merge autogenerated payload with constructor-specified payload


version 0.007


  package Example;
  use Moose;

  with qw(Role::HasPayload::Merged);

  sub Payload { 'Role::HasPayload::Meta::Attribute::Payload' }

  has height => (
    is => 'ro',
    traits   => [ Payload ],

  has width => (
    is => 'ro',
    traits   => [ Payload ],

  has color => (
    is => 'ro',


  my $example = Example->new({
    height  => 10,
    width   => 20,
    color   => 'blue',
    payload => { depth => 30 },

  $example->payload; # { height => 10, width => 20, depth => 30 }


Role::HasPayload::Merged provides a payload method and a payload attribute. It computes the result of the payload method when it's called, first by gathering the values of attributes marked with Role::HasPayload::Meta::Attribute::Payload, then by merging in the contents of the payload attribute (provided at construction).

If an entry in the constructor-provided payload already exists in the autogenerated payload, a warning is issued and the autogenerated value is used.

For a bit more on the autogenerated payload, see Role::HasPayload::Auto.

This role is especially useful when combined with Role::HasMessage::Errf.


This library should run on perls released even a long time ago. It should work on any version of perl released in the last five years.

Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.


Ricardo Signes <>


This software is copyright (c) 2022 by Ricardo Signes.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.