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