Articulate/Service/List.pm

filter: Statementstmt 60.4% 29 / 48 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 1 totaltotal 60.3% 38 / 63 SCAR 16.8
CC
4
Cov
56%
handle_list
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 5.4
« Articulate/Role/Sortation/AllYouNeedIsCmp.pm ↑ Summary Articulate/Sortation/MetaDelver.pm »
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 # The following provide objects which must be created on a per-request basis
9 1 ▶use Articulate::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Articulate::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 with 'Articulate::Role::Service';
14  
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 sub handle_list {
20 0 ▶ my $self = shift;
Subroutine handle_list: not called CC=4 SCAR=30.0
Pod undocumented
21 0 my $request = shift;
22  
23 0 my $location = loc $request->data->{location};
24 0 my $sort = $request->data->{sort}; # needs careful validation as this can do all sorts of fun constructor logic
25  
26 0 my $user = $request->user_id;
27 0 my $permission = $self->authorisation->permitted ( $user, read => $location );
28  
29 0 ▶ if ( $permission ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($permission) { } 0 0 0
30 0 my $items = [];
31 0 foreach my $item_location (map { loc "$location/$_" } $self->storage->list_items($location)) {
32 0 ▶ if ( $self->authorisation->permitted ( $user, read => $item_location ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->authorisation->permitted($user, "read", $item_location)) 0 0 0
33 0 my $item = $self->construction->construct( {
34 location => $item_location,
35 meta => $self->storage->get_meta($item_location),
36 content => $self->storage->get_content($item_location),
37 } );
38 0 $self->augmentation->augment ($item); # this will throw if it fails
39 0 push @$items, $item;
40 }
41 }
42 0 my $sorter = Articulate::Sortation::MetaDelver->new( $sort );
43 return response 'list', {
44 list => [
45 map {
46 {
47 is => $_->location->[-2],
48 location => $_->location,
49 schema => $_->meta->{schema},
50 0 content => $_->content,
51 }
52 }
53 0 @{ $sorter->schwartz($items) }
54 ],
55 };
56 }
57 else {
58 0 throw_error 'Forbidden' => $permission->reason;
59 }
60  
61 }
62  
63  
64 1 1;
« Articulate/Role/Sortation/AllYouNeedIsCmp.pm ↑ Summary Articulate/Sortation/MetaDelver.pm »