NAME

Throwable::X::AutoPayload - a thing that automatically computes its payload based on attributes

VERSION

version 0.003

SYNOPSIS

package X::Example;
use Moose;

with qw(Throwable::X::AutoPayload);

sub Payload { 'Throwable::X::Meta::Attribute::Payload' }

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

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

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

...then...

my $example = X::Example->new({
  height => 10,
  width  => 20,
  color  => 'blue',
});

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

DESCRIPTION

Throwable::X::AutoPayload only provides one method, payload, which returns a hashref of the name and value of every attribute on the object with the Throwable::X::Meta::Attribute::Payload trait. (The attribute value is gotten with the the method returned by the attribute's get_read_method method.)

This role is especially useful when combined with Throwable::X::WithMessage::Errf.

AUTHOR

Ricardo Signes <rjbs@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 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.