Silki/Role/Schema/Serializes.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 52 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Silki::Role::Schema::Serializes;
2 {
3 $Silki::Role::Schema::Serializes::VERSION = '0.29';
4 }
5  
6 use strict;
7 use warnings;
8 use namespace::autoclean;
9  
10 use Silki::Types qw( ArrayRef Str );
11  
12 use MooseX::Role::Parameterized;
13  
14 parameter skip => (
15 isa => ArrayRef [Str],
16 default => sub { [] },
17 );
18  
19 role {
20 my $p = shift;
21 my %extra = @_;
22  
23 my %skip = map { $_ => 1 } @{ $p->skip() };
24  
25 my %map;
26  
27 for my $attr ( $extra{consumer}->get_all_attributes() ) {
28  
29 next if $skip{ $attr->name() };
30 next if $attr->name() =~ /_raw$/;
31  
32 # We only want to serialize data from the class's the associated table
33 if ( $attr->isa('Fey::Meta::Attribute::FromInflator') ) {
34 $map{ $attr->name() } = $attr->raw_attribute()->name();
35 }
36 elsif ( $attr->isa('Fey::Meta::Attribute::FromColumn') ) {
37 $map{ $attr->name() } = $attr->name();
38 }
39 }
40  
41 method serialize => sub {
42 my $self = shift;
43  
44 return {
45 map {
46 my $meth = $map{$_};
47 $_ => $self->$meth();
48 } keys %map
49 };
50 };
51 };
52  
53 1;