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.087';
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   15331 use Mojo::Base '-role';
  23         69  
  23         443  
29 23     23   11782 use Mojo::Promise;
  23         60  
  23         342  
30              
31             sub _call_with_promise {
32 93     93   304 my ( $self, $method, @args ) = @_;
33 93         486 my @return = $self->$method( @args );
34 93         512 my $promise = Mojo::Promise->new;
35 93         3237 $promise->resolve( @return );
36             }
37              
38 43     43 0 212275 sub list_p { return _call_with_promise( shift, list => @_ ) }
39 25     25 0 41746 sub get_p { return _call_with_promise( shift, get => @_ ) }
40 10     10 0 43760 sub set_p { return _call_with_promise( shift, set => @_ ) }
41 10     10 0 36608 sub delete_p { return _call_with_promise( shift, delete => @_ ) }
42 5     5 0 23368 sub create_p { return _call_with_promise( shift, create => @_ ) }
43              
44             1;
45              
46             __END__