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