Raisin::Entity - A simple facade to use with your API
version 0.93
package MusicApp::Entity::Artist; use strict; use warnings; use Raisin::Entity; expose 'id'; expose 'name', as => 'artist'; expose 'website', if => sub { my $artist = shift; $artist->website; }; expose 'albums', using => 'MusicApp::Entity::Album'; expose 'hash', sub { my $artist = shift; my $hash = 0; my $name = blessed($artist) ? $artist->name : $artist->{name}; foreach (split //, $name) { $hash = $hash * 42 + ord($_); } $hash; }; 1;
Supports DBIx::Class, Rose::DB::Object and basic Perl data structures like SCALAR, ARRAY & HASH.
SCALAR
ARRAY
HASH
Define a fields that will be exposed.
The field lookup requests specified name
as an object method if it is a DBIx::Class or a Rose::DB::Object;
as a hash key;
die.
expose 'id';
Use using to expose a field with a presenter.
using
expose 'albums', using => 'MusicApp::Entity::Album';
You can use if to expose fields conditionally.
if
expose 'website', if => sub { my $artist = shift; blessed($artist) && $artist->can('website'); };
Supply a block to define a hash using nested exposures.
expose 'contact_info', sub { expose 'phone'; expose 'address', using => 'API::Address'; };
Use a subroutine to evaluate exposure at runtime.
expose 'hash', sub { my $artist = shift; my $hash; foreach (split //, $artist->name) { $hash = $hash * 42 + ord($_); } $hash; };
Expose under an alias with as.
as
expose 'name', as => 'artist';
expose 'name', documentation => { type => 'String', desc => 'Artists name' };
OpenAPI compatible specification generates automatically if OpenAPI/Swagger plugin enabled.
Artur Khabibullin
This software is copyright (c) 2019 by Artur Khabibullin.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Raisin, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Raisin
CPAN shell
perl -MCPAN -e shell install Raisin
For more information on module installation, please visit the detailed CPAN module installation guide.