Dancer2-Plugin-JsonApi/lib/Dancer2/Plugin/JsonApi/Registry.pm

39 lines
719 B
Perl

package Dancer2::Plugin::JsonApi::Registry;
use 5.32.0;
use Dancer2::Plugin::JsonApi::Schema;
use Carp;
use Moo;
use experimental qw/ signatures /;
sub serialize ( $self, $type, $data, $extra_data = {} ) {
return $self->type($type)->serialize( $data, $extra_data );
}
has types => (
is => 'ro',
default => sub { +{} },
);
has app => ( is => 'ro', );
sub add_type ( $self, $type, $definition = {} ) {
$self->{types}{$type} = Dancer2::Plugin::JsonApi::Schema->new(
registry => $self,
type => $type,
%$definition
);
}
sub type ( $self, $type ) {
return $self->types->{$type} //=
Dancer2::Plugin::JsonApi::Schema->new( type => $type );
}
1;
__END__