Lines 405-411
sub TO_JSON {
Link Here
|
405 |
elsif ( _numeric_column_type( $columns_info->{$col}->{data_type} ) |
405 |
elsif ( _numeric_column_type( $columns_info->{$col}->{data_type} ) |
406 |
and looks_like_number( $unblessed->{$col} ) |
406 |
and looks_like_number( $unblessed->{$col} ) |
407 |
) { |
407 |
) { |
408 |
|
|
|
409 |
# TODO: Remove once the solution for |
408 |
# TODO: Remove once the solution for |
410 |
# https://github.com/perl5-dbi/DBD-mysql/issues/212 |
409 |
# https://github.com/perl5-dbi/DBD-mysql/issues/212 |
411 |
# is ported to whatever distro we support by that time |
410 |
# is ported to whatever distro we support by that time |
Lines 415-421
sub TO_JSON {
Link Here
|
415 |
elsif ( _decimal_column_type( $columns_info->{$col}->{data_type} ) |
414 |
elsif ( _decimal_column_type( $columns_info->{$col}->{data_type} ) |
416 |
and looks_like_number( $unblessed->{$col} ) |
415 |
and looks_like_number( $unblessed->{$col} ) |
417 |
) { |
416 |
) { |
418 |
|
|
|
419 |
# TODO: Remove once the solution for |
417 |
# TODO: Remove once the solution for |
420 |
# https://github.com/perl5-dbi/DBD-mysql/issues/212 |
418 |
# https://github.com/perl5-dbi/DBD-mysql/issues/212 |
421 |
# is ported to whatever distro we support by that time |
419 |
# is ported to whatever distro we support by that time |
Lines 552-559
Returns a representation of the object, suitable for API output.
Link Here
|
552 |
sub to_api { |
550 |
sub to_api { |
553 |
my ( $self, $params ) = @_; |
551 |
my ( $self, $params ) = @_; |
554 |
|
552 |
|
555 |
return unless $self->is_accessible($params); |
|
|
556 |
|
557 |
my $json_object = $self->TO_JSON; |
553 |
my $json_object = $self->TO_JSON; |
558 |
|
554 |
|
559 |
# Make sure we duplicate the $params variable to avoid |
555 |
# Make sure we duplicate the $params variable to avoid |
Lines 585-590
sub to_api {
Link Here
|
585 |
} |
581 |
} |
586 |
} |
582 |
} |
587 |
|
583 |
|
|
|
584 |
# Remove forbidden attributes if required (including their coded values) |
585 |
if ( !$self->is_accessible($params) ) { |
586 |
for my $field ( keys %{$json_object} ) { |
587 |
unless ( any { $_ eq $field } @{ $self->unredact_list } ) { |
588 |
$json_object->{$field} = undef; |
589 |
} |
590 |
} |
591 |
|
592 |
if ($strings) { |
593 |
foreach my $field ( keys %{$string_map} ) { |
594 |
unless ( any { $_ eq $field } @{ $self->unredact_list } ) { |
595 |
$string_map->{$field} = undef; |
596 |
} |
597 |
} |
598 |
} |
599 |
} |
600 |
|
588 |
my $to_api_mapping = $self->to_api_mapping; |
601 |
my $to_api_mapping = $self->to_api_mapping; |
589 |
|
602 |
|
590 |
# Rename attributes and coded values if there's a mapping |
603 |
# Rename attributes and coded values if there's a mapping |
Lines 717-722
sub public_read_list
Link Here
|
717 |
return []; |
730 |
return []; |
718 |
} |
731 |
} |
719 |
|
732 |
|
|
|
733 |
=head3 unredact_list |
734 |
|
735 |
my @unredact_list = @{$object->unredact_list}; |
736 |
|
737 |
Generic method that returns the list of database columns that are allowed to |
738 |
be passed to render objects on the API when the user making the request should |
739 |
not ordinarily have unrestricted access to the data (as returned by the is_accesible method). |
740 |
|
741 |
Note: this only returns an empty I<arrayref>. Each class should have its |
742 |
own implementation. |
743 |
|
744 |
=cut |
745 |
|
746 |
sub unredact_list { |
747 |
return []; |
748 |
} |
749 |
|
720 |
=head3 from_api_mapping |
750 |
=head3 from_api_mapping |
721 |
|
751 |
|
722 |
my $mapping = $object->from_api_mapping; |
752 |
my $mapping = $object->from_api_mapping; |