line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Moo::Role::ToJSON; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
348488
|
use Types::Standard 'ArrayRef'; |
|
2
|
|
|
|
|
115729
|
|
|
2
|
|
|
|
|
19
|
|
4
|
2
|
|
|
2
|
|
1374
|
use Moo::Role; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
13
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# ABSTRACT: a Moo role for a TO_JSON method |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has serializable_attributes => ( |
11
|
|
|
|
|
|
|
is => 'lazy', |
12
|
|
|
|
|
|
|
isa => ArrayRef, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
23
|
sub _build_serializable_attributes { [] } |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub TO_JSON { |
18
|
6
|
|
|
6
|
1
|
19550
|
my $self = shift; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my @attributes_to_serialize |
21
|
|
|
|
|
|
|
= $self->can('is_attribute_serializable') |
22
|
6
|
|
|
|
|
124
|
? grep { $self->is_attribute_serializable($_) } @{$self->serializable_attributes} |
|
3
|
|
|
|
|
67
|
|
23
|
6
|
100
|
|
|
|
29
|
: @{$self->serializable_attributes}; |
|
3
|
|
|
|
|
45
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
return { |
26
|
6
|
|
|
|
|
129
|
map +($_ => $self->$_), @attributes_to_serialize |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
1; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
__END__ |