BackPAN/Index/Role/AsHash.pm

filter: Statementstmt 100% 10 / 10 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod 100% 1 / 1 totaltotal 100% 13 / 13 CC 2 SCAR 5.1
CC
2
Cov
100%
as_hash
2.0
BEGIN
1.0
CRAP 1.7
« BackPAN/Index/Role/Log.pm ↑ Summary BackPAN/Index/Database.pm »
1 package BackPAN::Index::Role::AsHash;
2  
3 10 ▶use Mouse::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 10 requires qw(data_methods);
6  
7 3 ▶sub as_hash {
Subroutine as_hash: called CC=2 SCAR=6.9
Pod documented
8 3 my $self = shift;
9  
10 3 my %data;
11 3 for my $method ($self->data_methods) {
12 17 $data{$method} = $self->$method;
13 }
14  
15 3 return \%data;
16 }
17  
18  
19 =head1 NAME
20  
21 BackPAN::Index::Role::AsHash - Role to dump object data as a hash
22  
23 =head1 SYNOPSIS
24  
25 use BackPAN::Index::Role::AsHash;
26  
27 sub data_methods { return qw(list of data methods) }
28  
29 =head1 DESCRIPTION
30  
31 A role to implement C<<as_hash>> in result objects.
32  
33 =head2 Requires
34  
35 The receiving class must implement...
36  
37 =head3 data_methods
38  
39 my @methods = $self->data_methods;
40  
41 Returns a list of methods which get data about the object.
42  
43 =head2 Implements
44  
45 =head3 as_hash
46  
47 my $hash = $self->as_hash;
48  
49 Produces a hash reference representing the object's data based on
50 C<<$self->data_methods>>. Each key is a method name, the value is
51 C<<$self->$method>>.
52  
53 =cut
54  
55 10 1;
« BackPAN/Index/Role/Log.pm ↑ Summary BackPAN/Index/Database.pm »