| BackPAN-Index documentation | Contained in the BackPAN-Index distribution. |
BackPAN::Index::Role::AsHash - Role to dump object data as a hash
use BackPAN::Index::Role::AsHash;
sub data_methods { return qw(list of data methods) }
A role to implement <as_hash> in result objects.
The receiving class must implement...
my @methods = $self->data_methods;
Returns a list of methods which get data about the object.
my $hash = $self->as_hash;
Produces a hash reference representing the object's data based on
<$self-data_methods>>. Each key is a method name, the value is
<$self-$method>>.
| BackPAN-Index documentation | Contained in the BackPAN-Index distribution. |
package BackPAN::Index::Role::AsHash; use strict; use warnings; use base 'Exporter'; our @EXPORT = qw(as_hash); our @REQUIRED = qw(data_methods); use CLASS; sub as_hash { my $self = shift; my %data; for my $method ($self->data_methods) { $data{$method} = $self->$method; } return \%data; }
1;