| 1 | package WebAPI::DBIC::Resource::Role::SetWritable; | ||||||||||||||||||||
| 2 | 25 | $WebAPI::DBIC::Resource::Role::SetWritable::VERSION = '0.004002'; | |||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 25 | ▶ | use Devel::Dwarn; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 25 | ▶ | use Carp qw(confess); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 25 | ▶ | use Moo::Role; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 25 | requires 'render_set_as_plain'; | |||||||||||||||||||
| 11 | 25 | requires 'render_item_into_body'; | |||||||||||||||||||
| 12 | 25 | requires 'decode_json'; | |||||||||||||||||||
| 13 | 25 | requires 'set'; | |||||||||||||||||||
| 14 | 25 | requires 'prefetch'; | |||||||||||||||||||
| 15 | 25 | requires 'writable'; | |||||||||||||||||||
| 16 | 25 | requires 'path_for_item'; | |||||||||||||||||||
| 17 | 25 | requires 'allowed_methods'; | |||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 25 | has item => ( # for POST to create | |||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 25 | has content_types_accepted => ( | |||||||||||||||||||
| 25 | is => 'lazy', | ||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 11 | ▶ | sub _build_content_types_accepted { | ||||||||||||||||||
|
Subroutine
_build_content_types_accepted: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | 11 | return [ {'application/vnd.wapid+json' => 'from_plain_json'} ] | |||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 69 | ▶ | around 'allowed_methods' => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||
| 33 | 69 | my $orig = shift; | |||||||||||||||||||
| 34 | 69 | my $self = shift; | |||||||||||||||||||
| 35 | 69 | my $methods = $self->$orig(); | |||||||||||||||||||
| 36 | 69 | ▶ | push @$methods, 'POST' if $self->writable; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 37 | 69 | return $methods; | |||||||||||||||||||
| 38 | 25 | }; | |||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 11 | ▶ | sub post_is_create { return 1 } | ||||||||||||||||||
|
Subroutine
post_is_create: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 22 | ▶ | sub create_path_after_handler { return 1 } | ||||||||||||||||||
|
Subroutine
create_path_after_handler: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 6 | ▶ | sub from_plain_json { | ||||||||||||||||||
|
Subroutine
from_plain_json: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 47 | 6 | my $self = shift; | |||||||||||||||||||
| 48 | 6 | my $item = $self->create_resource( $self->decode_json($self->request->content) ); | |||||||||||||||||||
| 49 | 6 | return $self->item($item); | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 11 | ▶ | sub create_path { | ||||||||||||||||||
|
Subroutine
create_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 54 | 11 | my $self = shift; | |||||||||||||||||||
| 55 | 11 | return $self->path_for_item($self->item); | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 6 | ▶ | sub create_resource { | ||||||||||||||||||
|
Subroutine
create_resource: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||
| 60 | 6 | my ($self, $data) = @_; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 6 | my $item = $self->set->create($data); | |||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | # resync with what's (now) in the db to pick up defaulted fields etc | ||||||||||||||||||||
| 65 | 6 | $item->discard_changes(); | |||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | # called here because create_path() is too late for Web::Machine | ||||||||||||||||||||
| 68 | $self->render_item_into_body(item => $item) | ||||||||||||||||||||
| 69 | 6 | ▶ | if grep {defined $_->{self}} @{$self->prefetch||[]}; | ||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->prefetch || []
MC/DC0%0/1
$self->prefetch || []
$self->prefetch
Truth table50%1/2
A
A= $self->prefetch
| |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | 6 | return $item; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 25 | 1; | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||