formatting
This commit is contained in:
parent
83e2f01add
commit
250bd940da
@ -73,9 +73,7 @@ sub serialize ( $self, $data, $extra_data = {} ) {
|
||||
|
||||
sub dedupe_included {
|
||||
my %seen;
|
||||
return grep {
|
||||
not $seen{$_->{type}}{$_->{id}}++
|
||||
} @_;
|
||||
return grep { not $seen{ $_->{type} }{ $_->{id} }++ } @_;
|
||||
}
|
||||
|
||||
=head2 serialize_data($data,$extra_data)
|
||||
@ -86,14 +84,17 @@ Serializes the inner C<$data>.
|
||||
|
||||
sub serialize_data ( $self, $data, $extra_data = {}, $included = undef ) {
|
||||
|
||||
return [ map { $self->serialize_data($_,$extra_data, $included) } @$data ] if ref $data eq 'ARRAY';
|
||||
return [ map { $self->serialize_data( $_, $extra_data, $included ) }
|
||||
@$data ]
|
||||
if ref $data eq 'ARRAY';
|
||||
|
||||
# it's a scalar? it's the id
|
||||
return { id => $data, type => $self->type } unless ref $data;
|
||||
|
||||
my $s = {
|
||||
type => $self->type,
|
||||
id => $self->gen_id($data) };
|
||||
id => $self->gen_id($data)
|
||||
};
|
||||
|
||||
if ( $self->links ) {
|
||||
$s->{links} = gen_links( $self->links, $data, $extra_data );
|
||||
@ -108,14 +109,15 @@ sub serialize_data ( $self, $data, $extra_data = {}, $included = undef ) {
|
||||
|
||||
my @inc;
|
||||
|
||||
my $t = $self->registry->serialize(
|
||||
$relationships{$key}{type}, $attr, \@inc
|
||||
);
|
||||
my $t = $self->registry->serialize( $relationships{$key}{type},
|
||||
$attr, \@inc );
|
||||
|
||||
$s->{relationships}{$key}{data} = obj_ref( $t->{data}, \@inc );
|
||||
|
||||
if ( my $links = $relationships{$key}{links} ) {
|
||||
$s->{relationships}{$key}{links} = gen_links($links,$s->{relationships}{ $key }{data}, $extra_data );
|
||||
$s->{relationships}{$key}{links} =
|
||||
gen_links( $links, $s->{relationships}{$key}{data},
|
||||
$extra_data );
|
||||
}
|
||||
|
||||
push @$included, @inc if $included;
|
||||
@ -124,8 +126,9 @@ sub serialize_data ( $self, $data, $extra_data = {}, $included = undef ) {
|
||||
delete $s->{attributes} unless $s->{attributes}->%*;
|
||||
|
||||
if ( $self->allowed_attributes ) {
|
||||
delete $s->{attributes}{$_} for (
|
||||
set( keys $s->{attributes}->%* ) - set($self->allowed_attributes->@* ) )->@*;
|
||||
delete $s->{attributes}{$_}
|
||||
for ( set( keys $s->{attributes}->%* ) -
|
||||
set( $self->allowed_attributes->@* ) )->@*;
|
||||
}
|
||||
|
||||
return $s;
|
||||
@ -133,7 +136,8 @@ sub serialize_data ( $self, $data, $extra_data = {}, $included = undef ) {
|
||||
}
|
||||
|
||||
sub obj_ref ( $data, $included ) {
|
||||
return [ map { obj_ref($_,$included) } @$data ] if ref $data eq 'ARRAY';
|
||||
return [ map { obj_ref( $_, $included ) } @$data ]
|
||||
if ref $data eq 'ARRAY';
|
||||
|
||||
return $data if keys %$data == 2;
|
||||
|
||||
@ -152,9 +156,7 @@ sub gen_links($links,$data,$extra_data={}) {
|
||||
|
||||
return $links->( $data, $extra_data ) if ref $links eq 'CODE';
|
||||
|
||||
return {
|
||||
pairmap { $a => gen_item($b, $data,$extra_data) } %$links
|
||||
};
|
||||
return { pairmap { $a => gen_item( $b, $data, $extra_data ) } %$links };
|
||||
}
|
||||
|
||||
sub gen_item ( $item, $data, $extra_data ) {
|
||||
|
Loading…
Reference in New Issue
Block a user