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 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 =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
31 L<Articulate::Service::Simple> with the exception that nothing is
32 written.
33  
34 Throws an error if the content already exists or if the user has no
35 write permission on that location.
36  
37 =cut
38  
39 0 ▶sub handle_preview {
Subroutine handle_preview: not called CC=5 SCAR=34.0
Pod documented
40 0 my $self = shift;
41 0 my $request = shift;
42  
43 my $item =
44 blessed $request->data
45 ? $request->data
46 : $self->construction->construct(
47 0 ▶ { ( %{ $request->data } ? %{ $request->data } : () ), } );
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($request->data) ? : 0 0 0
%{$request->data;} ? : 0 0 0
48  
49 0 my $location = $item->location;
50  
51 0 my $user = $request->user_id;
52 0 my $permission = $self->authorisation->permitted( $user, write => $location );
53  
54 0 ▶ if ($permission)
Branch: 1 branch
BranchTrueFalseTotal
if ($permission) { } 0 0 0
55 { # no point offering this service to people who can't write there
56  
57 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
58 or throw_error BadRequest => 'The content did not validate'; # or throw
59 0 $self->enrichment->enrich( $item, $request ); # this will throw if it fails
60  
61 # skip the storage interaction
62 0 my $item_class = $item->location->[-2];
63  
64 0 $self->augmentation->augment($item_class); # this will throw if it fails
65  
66 return new_response $item_class, {
67 $item_class => {
68 schema => $item->meta->{schema},
69 0 content => $item->content,
70 location => $item->location, # as string or arrayref?
71 },
72 };
73 }
74 else {
75 0 throw_error Forbidden => $permission->reason;
76 }
77 }
78  
79 6 1;
« Articulate/Serialisation.pm ↑ Summary Articulate/Augmentation/Interpreter.pm »