File Coverage

examples/sample-app/lib/RESTApp/Host.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package RESTApp::Host;
2              
3 1     1   430 use strict;
  1         2  
  1         24  
4 1     1   4 use warnings;
  1         13  
  1         23  
5              
6 1     1   4 use Raisin::API;
  1         1  
  1         5  
7 1     1   413 use UseCase::Host;
  1         2  
  1         28  
8              
9 1     1   5 use Types::Standard qw(Int Str);
  1         2  
  1         5  
10              
11             desc 'Operations about host';
12             resource hosts => sub {
13             summary 'List hosts';
14             params(
15             optional('start', type => Int, default => 0, desc => 'Pager start'),
16             optional('count', type => Int, default => 10, desc => 'Pager count'),
17             );
18             get sub {
19             my $params = shift;
20             my @hosts = UseCase::Host::list(%$params);
21             { data => RESTApp::paginate(\@hosts, $params) }
22             };
23              
24             summary 'Create a new host';
25             params(
26             requires('name', type => Str, desc => 'Host name'),
27             requires('user_id', type => Int, desc => 'Host owner'),
28             optional('state', type => Str, desc => 'Host state')
29             );
30             post sub {
31             my $params = shift;
32             { success => UseCase::Host::create(%$params) }
33             };
34              
35             params(
36             requires('id', type => Int, desc => 'Host ID')
37             );
38             route_param id => sub {
39             summary 'Show a host';
40             get sub {
41             my $params = shift;
42             { data => UseCase::Host::show($params->{id}) }
43             };
44              
45             summary 'Edit a host';
46             params(
47             requires('state', type => Str, desc => 'Host state'),
48             );
49             put sub {
50             my $params = shift;
51             { data => UseCase::Host::edit($params->{id}, %$params) }
52             };
53              
54             summary 'Edit a host';
55             params(
56             requires('state', type => Str, desc => 'Host state'),
57             );
58             patch sub {
59             my $params = shift;
60             { data => UseCase::Host::edit($params->{id}, %$params) }
61             };
62              
63              
64             summary 'Delete a host';
65             del sub {
66             my $params = shift;
67             { success => UseCase::Host::remove($params->{id}) }
68             }
69             };
70             };
71              
72             1;