line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Articulate::Service::SimplePreviews; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
3801
|
use strict; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
215
|
|
4
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
141
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
26
|
use Articulate::Syntax; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
41
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
8027
|
use Moo; |
|
6
|
|
|
|
|
13
|
|
|
6
|
|
|
|
|
33
|
|
9
|
|
|
|
|
|
|
with 'Articulate::Role::Service'; |
10
|
|
|
|
|
|
|
|
11
|
6
|
|
|
6
|
|
1899
|
use Try::Tiny; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
367
|
|
12
|
6
|
|
|
6
|
|
32
|
use Scalar::Util qw(blessed); |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
1455
|
|
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 verb in |
31
|
|
|
|
|
|
|
L 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
|
|
|
|
|
|
|
sub handle_preview { |
40
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
41
|
0
|
|
|
|
|
|
my $request = shift; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $item = |
44
|
|
|
|
|
|
|
blessed $request->data |
45
|
|
|
|
|
|
|
? $request->data |
46
|
|
|
|
|
|
|
: $self->construction->construct( |
47
|
0
|
0
|
|
|
|
|
{ ( %{ $request->data } ? %{ $request->data } : () ), } ); |
|
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
|
0
|
|
|
|
|
if ($permission) |
55
|
|
|
|
|
|
|
{ # no point offering this service to people who can't write there |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
$self->validation->validate($item) |
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
|
0
|
|
|
|
|
|
return new_response $item_class, { |
67
|
|
|
|
|
|
|
$item_class => { |
68
|
|
|
|
|
|
|
schema => $item->meta->{schema}, |
69
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
1; |