| 1 | package Articulate::Service::SimpleForms; | ||||||||||
| 2 | |||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 4 | ▶ | use Articulate::Syntax; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 4 | with 'Articulate::Role::Service'; | |||||||||
| 10 | |||||||||||
| 11 | |||||||||||
| 12 | 4 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 4 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | |||||||||||
| 15 | sub handle_create_form { | ||||||||||
| 16 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
handle_create_form: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 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 | ▶ | if ( $permission ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
handle_upload_form: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 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 | ▶ | if ( $permission ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
handle_edit_form: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 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 | ▶ | if ( $permission ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | 0 | ▶ | throw_error 'NotFound' unless $self->storage->item_exists($location); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ▶ | my $self = shift; | ||||||||
|
Subroutine
handle_delete_form: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 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 | ▶ | if ( $self->authorisation->permitted ( $user, write => $location ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 0 | ▶ | throw_error 'NotFound' unless $self->storage->item_exists($location); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | |||||||||||
| 98 | 0 | my $item = $self->storage->get_item($location); | |||||||||
| 99 | 0 | my $item_class = $item->location->[-2]; | |||||||||
| 100 | 0 | ▶ | $self->augmentation->augment ($item) or throw_error 'Internal'; # or throw | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | |||||||||||
| 102 | return response 'form/delete', { | ||||||||||
| 103 | $item_class => { | ||||||||||
| 104 | schema => $item->meta->{schema}, | ||||||||||
| 105 | 0 | 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 | 4 | 1; | |||||||||