Articulate/Service/SimplePreviews.pm

filter: Statementstmt 57.1% 20 / 35 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 52.9% 27 / 51 CC 5 SCAR 26.5
CC
5
Cov
47%
handle_preview
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 14.2
« Articulate/Serialisation.pm ↑ Summary Articulate/Augmentation/Interpreter.pm »
1 package Articulate::Service::SimplePreviews;
2  
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 5 ▶use Articulate::Syntax;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 with 'Articulate::Role::Service';
10  
11 5 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 Articulate::Service::SimplePreviews - provide preview
17  
18 =cut
19  
20 =head1 METHODS
21  
22 =head3 handle_preview
23  
24 preview => {
25 meta => {}
26 content => '...',
27 location => '...'
28 }
29  
30 This is in almost all respects identical to the C<create> verb in L<Articulate::Service::Simple> with the exception that nothing is written.
31  
32 Throws an error if the content already exists or if the user has no write permission on that location.
33  
34 =cut
35  
36 sub handle_preview {
37 0 ▶ my $self = shift;
Subroutine handle_preview: not called CC=5 SCAR=34.0
Pod documented
38 0 my $request = shift;
39  
40 my $item =
41 blessed $request->data
42 ? $request->data
43 : $self->construction->construct(
44 0 ▶ { ( %{ $request->data } ? %{ $request->data } : () ), } );
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($request->data) ? : 0 0 0
%{$request->data;} ? : 0 0 0
45  
46 0 my $location = $item->location;
47  
48 0 my $user = $request->user_id;
49 0 my $permission = $self->authorisation->permitted( $user, write => $location );
50  
51 0 ▶ if ($permission)
Branch: 1 branch
BranchTrueFalseTotal
if ($permission) { } 0 0 0
52 { # no point offering this service to people who can't write there
53  
54 0 ▶ $self->validation->validate($item)
Branch: 1 branch
BranchTrueFalseTotal
$self->validation->validate($item) or throw_error("BadRequest", "The content did not validate") 0 0 0
55 or throw_error BadRequest => 'The content did not validate'; # or throw
56 0 $self->enrichment->enrich( $item, $request ); # this will throw if it fails
57  
58 # skip the storage interaction
59 0 my $item_class = $item->location->[-2];
60  
61 0 $self->augmentation->augment($item_class); # this will throw if it fails
62  
63 return response $item_class, {
64 $item_class => {
65 schema => $item->meta->{schema},
66 0 content => $item->content,
67 location => $item->location, # as string or arrayref?
68 },
69 };
70 }
71 else {
72 0 throw_error Forbidden => $permission->reason;
73 }
74 }
75  
76 5 1;
« Articulate/Serialisation.pm ↑ Summary Articulate/Augmentation/Interpreter.pm »