Role::HasPayload::Auto - a thing that automatically computes its payload based on attributes
version 0.007
package Example; use Moose; with qw(Role::HasPayload::Auto); sub Payload { 'Role::HasPayload::Meta::Attribute::Payload' } has height => ( is => 'ro', traits => [ Payload ], ); has width => ( is => 'ro', traits => [ Payload ], ); has color => ( is => 'ro', );
...then...
my $example = Example->new({ height => 10, width => 20, color => 'blue', }); $example->payload; # { height => 10, width => 20 }
Role::HasPayload::Auto only provides one method, payload, which returns a hashref of the name and value of every attribute on the object with the Role::HasPayload::Meta::Attribute::Payload trait. (The attribute value is gotten with the the method returned by the attribute's get_read_method method.)
payload
get_read_method
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 <cpan@semiotic.systems>
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.
To install Role::HasPayload, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Role::HasPayload
CPAN shell
perl -MCPAN -e shell install Role::HasPayload
For more information on module installation, please visit the detailed CPAN module installation guide.