| 1 | package Articulate::Service::List; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | ▶ | use Articulate::Syntax; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Articulate::Sortation::MetaDelver; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # The following provide objects which must be created on a per-request basis | ||||||||||
| 10 | 1 | ▶ | use Articulate::Request; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Articulate::Response; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | with 'Articulate::Role::Service'; | |||||||||
| 15 | |||||||||||
| 16 | 1 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | sub handle_list { | ||||||||
|
Subroutine
handle_list: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 20 | 0 | my $self = shift; | |||||||||
| 21 | 0 | my $request = shift; | |||||||||
| 22 | |||||||||||
| 23 | 0 | my $location = new_location $request->data->{location}; | |||||||||
| 24 | my $sort = $request->data->{sort} | ||||||||||
| 25 | 0 | ; # needs careful validation as this can do all sorts of fun constructor logic | |||||||||
| 26 | |||||||||||
| 27 | 0 | my $user = $request->user_id; | |||||||||
| 28 | 0 | my $permission = $self->authorisation->permitted( $user, read => $location ); | |||||||||
| 29 | |||||||||||
| 30 | 0 | ▶ | if ($permission) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | my $items = []; | |||||||||
| 32 | 0 | foreach my $item_location ( map { new_location "$location/$_" } | |||||||||
| 33 | $self->storage->list_items($location) ) | ||||||||||
| 34 | { | ||||||||||
| 35 | 0 | ▶ | if ( $self->authorisation->permitted( $user, read => $item_location ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 36 | 0 | my $item = $self->construction->construct( | |||||||||
| 37 | { | ||||||||||
| 38 | location => $item_location, | ||||||||||
| 39 | meta => $self->storage->get_meta($item_location), | ||||||||||
| 40 | content => $self->storage->get_content($item_location), | ||||||||||
| 41 | } | ||||||||||
| 42 | ); | ||||||||||
| 43 | 0 | $self->augmentation->augment($item); # this will throw if it fails | |||||||||
| 44 | 0 | push @$items, $item; | |||||||||
| 45 | } | ||||||||||
| 46 | } | ||||||||||
| 47 | 0 | my $sorter = Articulate::Sortation::MetaDelver->new($sort); | |||||||||
| 48 | return new_response 'list', { | ||||||||||
| 49 | list => [ | ||||||||||
| 50 | map { | ||||||||||
| 51 | { | ||||||||||
| 52 | is => $_->location->[-2], | ||||||||||
| 53 | location => $_->location, | ||||||||||
| 54 | schema => $_->meta->{schema}, | ||||||||||
| 55 | 0 | content => $_->content, | |||||||||
| 56 | } | ||||||||||
| 57 | 0 | } @{ $sorter->schwartz($items) } | |||||||||
| 58 | ], | ||||||||||
| 59 | }; | ||||||||||
| 60 | } | ||||||||||
| 61 | else { | ||||||||||
| 62 | 0 | throw_error 'Forbidden' => $permission->reason; | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | 1 | 1; | |||||||||