File Coverage

blib/lib/Articulate/Service/SimpleForms.pm
Criterion Covered Total %
statement 18 57 31.5
branch 0 14 0.0
condition n/a
subroutine 6 10 60.0
pod 0 4 0.0
total 24 85 28.2


line stmt bran cond sub pod time code
1             package Articulate::Service::SimpleForms;
2              
3 5     5   2692 use strict;
  5         8  
  5         166  
4 5     5   23 use warnings;
  5         5  
  5         105  
5              
6 5     5   19 use Articulate::Syntax;
  5         8  
  5         29  
7              
8 5     5   6937 use Moo;
  5         12  
  5         28  
9             with 'Articulate::Role::Service';
10              
11 5     5   1389 use Try::Tiny;
  5         10  
  5         247  
12 5     5   18 use Scalar::Util qw(blessed);
  5         10  
  5         2271  
13              
14             sub handle_create_form {
15 0     0 0   my $self = shift;
16 0           my $request = shift;
17 0           my $user = $request->user_id;
18 0           my $location = loc $request->data->{location};
19 0           my $permission = $self->authorisation->permitted( $user, write => $location );
20              
21 0 0         if ($permission) {
22              
23 0           return response 'form/create', {
24             form => {
25             location => loc $location, # as string or arrayref?
26             },
27             };
28             }
29             else {
30 0           throw_error Forbidden => $permission->reason;
31             }
32              
33             }
34              
35             sub handle_upload_form {
36 0     0 0   my $self = shift;
37 0           my $request = shift;
38 0           my $user = $request->user_id;
39 0           my $location = loc $request->data->{location};
40 0           my $permission = $self->authorisation->permitted( $user, write => $location );
41              
42 0 0         if ($permission) {
43              
44 0           return response 'form/upload', {
45             form => {
46             location => loc $location, # as string or arrayref?
47             },
48             };
49             }
50             else {
51 0           throw_error Forbidden => $permission->reason;
52             }
53             }
54              
55             sub handle_edit_form {
56 0     0 0   my $self = shift;
57 0           my $request = shift;
58              
59 0           my $location = loc $request->data->{location};
60 0           my $user = $request->user_id;
61 0           my $permission = $self->authorisation->permitted( $user, write => $location );
62              
63 0 0         if ($permission) {
64              
65 0 0         throw_error 'NotFound' unless $self->storage->item_exists($location);
66              
67 0           my $item = $self->storage->get_item($location);
68              
69             # we don't want to interpret at this point
70              
71 0           return response 'form/edit', {
72             raw => {
73             meta => $item->meta,
74             content => $item->content,
75             location => $item->location, # as string or arrayref?
76             },
77             };
78             }
79             else {
80 0           throw_error Forbidden => $permission->reason;
81             }
82              
83             }
84              
85             sub handle_delete_form {
86 0     0 0   my $self = shift;
87 0           my $request = shift;
88              
89 0           my $item = $request->data;
90 0           my $location = $item->location;
91 0           my $user = $request->user_id;
92 0           my $permission = $self->authorisation->permitted( $user, write => $location );
93              
94 0 0         if ( $self->authorisation->permitted( $user, write => $location ) ) {
95 0 0         throw_error 'NotFound' unless $self->storage->item_exists($location);
96              
97 0           my $item = $self->storage->get_item($location);
98 0           my $item_class = $item->location->[-2];
99 0 0         $self->augmentation->augment($item) or throw_error 'Internal'; # or throw
100              
101 0           return response 'form/delete', {
102             $item_class => {
103             schema => $item->meta->{schema},
104             content => $item->content,
105             location => $item->location, # as string or arrayref?
106             },
107             };
108             }
109             else {
110 0           throw_error Forbidden => $permission->reason;
111             }
112              
113             }
114              
115             1;