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 6     6   3280 use strict;
  6         11  
  6         197  
4 6     6   25 use warnings;
  6         7  
  6         125  
5              
6 6     6   26 use Articulate::Syntax;
  6         8  
  6         41  
7              
8 6     6   7481 use Moo;
  6         11  
  6         38  
9             with 'Articulate::Role::Service';
10              
11 6     6   1784 use Try::Tiny;
  6         9  
  6         319  
12 6     6   28 use Scalar::Util qw(blessed);
  6         16  
  6         2699  
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 = new_location $request->data->{location};
19 0           my $permission = $self->authorisation->permitted( $user, write => $location );
20              
21 0 0         if ($permission) {
22              
23 0           return new_response 'form/create', {
24             form => {
25             location => new_location $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 = new_location $request->data->{location};
40 0           my $permission = $self->authorisation->permitted( $user, write => $location );
41              
42 0 0         if ($permission) {
43              
44 0           return new_response 'form/upload', {
45             form => {
46             location => new_location $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 = new_location $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 new_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 new_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;