File Coverage

blib/lib/Articulate/Service/List.pm
Criterion Covered Total %
statement 27 46 58.7
branch 0 4 0.0
condition n/a
subroutine 9 10 90.0
pod 0 1 0.0
total 36 61 59.0


line stmt bran cond sub pod time code
1             package Articulate::Service::List;
2              
3 1     1   1758 use strict;
  1         2  
  1         35  
4 1     1   4 use warnings;
  1         2  
  1         21  
5              
6 1     1   3 use Articulate::Syntax;
  1         2  
  1         5  
7 1     1   1249 use Articulate::Sortation::MetaDelver;
  1         2  
  1         26  
8              
9             # The following provide objects which must be created on a per-request basis
10 1     1   4 use Articulate::Request;
  1         1  
  1         6  
11 1     1   248 use Articulate::Response;
  1         3  
  1         8  
12              
13 1     1   251 use Moo;
  1         2  
  1         5  
14             with 'Articulate::Role::Service';
15              
16 1     1   276 use Try::Tiny;
  1         3  
  1         53  
17 1     1   4 use Scalar::Util qw(blessed);
  1         1  
  1         302  
18              
19             sub handle_list {
20 0     0 0   my $self = shift;
21 0           my $request = shift;
22              
23 0           my $location = loc $request->data->{location};
24 0           my $sort = $request->data->{sort}
25             ; # 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 0         if ($permission) {
31 0           my $items = [];
32 0           foreach my $item_location ( map { loc "$location/$_" }
  0            
33             $self->storage->list_items($location) )
34             {
35 0 0         if ( $self->authorisation->permitted( $user, read => $item_location ) ) {
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 0           return response 'list', {
49             list => [
50             map {
51 0           {
52             is => $_->location->[-2],
53             location => $_->location,
54             schema => $_->meta->{schema},
55             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;