| 1 | package Yancy::Backend::Role::Sync; | ||
| 2 | 23 | our $VERSION = '1.088'; | |
| 3 | # ABSTRACT: A role to give a synchronous backend useful Promises methods | ||
| 4 | |||
| 5 | #pod =head1 SYNOPSIS | ||
| 6 | #pod | ||
| 7 | #pod package Yancy::Backend::SyncOnly; | ||
| 8 | #pod with 'Yancy::Backend::Role::Sync'; | ||
| 9 | #pod | ||
| 10 | #pod package main; | ||
| 11 | #pod my $be = Yancy::Backend::SyncOnly->new; | ||
| 12 | #pod my $promise = $be->create_p( \%item ); | ||
| 13 | #pod | ||
| 14 | #pod =head1 DESCRIPTION | ||
| 15 | #pod | ||
| 16 | #pod This role implements C<list_p>, C<get_p>, C<set_p>, C<delete_p>, and | ||
| 17 | #pod C<create_p> methods that return L<Mojo::Promise> objects for synchronous | ||
| 18 | #pod backends. This does not make the backend asynchronous: The original, | ||
| 19 | #pod synchronous method is called and a promise object created from the | ||
| 20 | #pod result. The promise is then returned already fulfilled. | ||
| 21 | #pod | ||
| 22 | #pod =head1 SEE ALSO | ||
| 23 | #pod | ||
| 24 | #pod L<Yancy::Backend> | ||
| 25 | #pod | ||
| 26 | #pod =cut | ||
| 27 | |||
| 28 | 23 | ▶ | use Mojo::Base '-role'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 29 | 23 | ▶ | use Mojo::Promise; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 30 | |||
| 31 | 93 | ▶ | sub _call_with_promise { |
|
Subroutine
_call_with_promise: called CC=1 SCAR=0.0
| |||
| 32 | 93 | my ( $self, $method, @args ) = @_; | |
| 33 | 93 | my @return = $self->$method( @args ); | |
| 34 | 93 | my $promise = Mojo::Promise->new; | |
| 35 | 93 | $promise->resolve( @return ); | |
| 36 | } | ||
| 37 | |||
| 38 | 43 | ▶ | sub list_p { return _call_with_promise( shift, list => @_ ) } |
|
Subroutine
list_p: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 39 | 25 | ▶ | sub get_p { return _call_with_promise( shift, get => @_ ) } |
|
Subroutine
get_p: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 40 | 10 | ▶ | sub set_p { return _call_with_promise( shift, set => @_ ) } |
|
Subroutine
set_p: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 41 | 10 | ▶ | sub delete_p { return _call_with_promise( shift, delete => @_ ) } |
|
Subroutine
delete_p: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 42 | 5 | ▶ | sub create_p { return _call_with_promise( shift, create => @_ ) } |
|
Subroutine
create_p: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 43 | |||
| 44 | 23 | 1; | |
| 45 | |||
| 46 | __END__ | ||