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 SCAR 21.8
CC
5
Cov
47%
handle_preview
30.0
BEGIN
1.0
BEGIN
1.0
CRAP 8.8
« Articulate/Authentication.pm ↑ Summary Articulate/Location.pm »
1 package Articulate::Service::SimplePreviews;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Articulate::Syntax;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 with 'Articulate::Role::Service';
10  
11 4 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶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 = blessed $request->data ? $request->data : $self->construction->construct( {
41 0 ▶ (%{$request->data} ? %{$request->data} : ()),
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($request->data) ? : 0 0 0
%{$request->data;} ? : 0 0 0
42 } );
43  
44 0 my $location = $item->location;
45  
46 0 my $user = $request->user_id;
47 0 my $permission = $self->authorisation->permitted ( $user, write => $location );
48  
49 0 ▶ if ( $permission ) { # no point offering this service to people who can't write there
Branch: 1 branch
BranchTrueFalseTotal
if ($permission) { } 0 0 0
50  
51 0 ▶ $self->validation->validate ($item) or throw_error BadRequest => 'The content did not validate'; # or throw
Branch: 1 branch
BranchTrueFalseTotal
$self->validation->validate($item) or throw_error("BadRequest", "The content did not validate") 0 0 0
52 0 $self->enrichment->enrich ($item, $request); # this will throw if it fails
53  
54 # skip the storage interaction
55 0 my $item_class = $item->location->[-2];
56  
57 0 $self->augmentation->augment ($item_class); # this will throw if it fails
58  
59 return response $item_class, {
60 $item_class => {
61 schema => $item->meta->{schema},
62 0 content => $item->content,
63 location => $item->location, # as string or arrayref?
64 },
65 };
66 }
67 else {
68 0 throw_error Forbidden => $permission->reason;
69 }
70 }
71  
72 4 1;
« Articulate/Authentication.pm ↑ Summary Articulate/Location.pm »