File Coverage

blib/lib/Yancy/Backend/Role/Sync.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod 0 5 0.0
total 23 28 82.1


line stmt bran cond sub pod time code
1             package Yancy::Backend::Role::Sync;
2             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, C, C, C, and
17             #pod C methods that return L 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
25             #pod
26             #pod =cut
27              
28 23     23   13732 use Mojo::Base '-role';
  23         67  
  23         366  
29 23     23   10693 use Mojo::Promise;
  23         63  
  23         307  
30              
31             sub _call_with_promise {
32 93     93   263 my ( $self, $method, @args ) = @_;
33 93         345 my @return = $self->$method( @args );
34 93         392 my $promise = Mojo::Promise->new;
35 93         2835 $promise->resolve( @return );
36             }
37              
38 43     43 0 202555 sub list_p { return _call_with_promise( shift, list => @_ ) }
39 25     25 0 39362 sub get_p { return _call_with_promise( shift, get => @_ ) }
40 10     10 0 41396 sub set_p { return _call_with_promise( shift, set => @_ ) }
41 10     10 0 35376 sub delete_p { return _call_with_promise( shift, delete => @_ ) }
42 5     5 0 22019 sub create_p { return _call_with_promise( shift, create => @_ ) }
43              
44             1;
45              
46             __END__