DBIC/Resource/ActiveModel/Role/SetWritable.pm

filter: Statementstmt 57.8% 22 / 38 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 2 totaltotal 47.2% 26 / 55 CC 4 SCAR 21.0
CC
4
Cov
50%
__ANON__
20.0
from_activemodel_json
2.0
create_resources_from_activemodel
2.0
CRAP 8.2
« DBIC/Resource/Role/SetInvoke.pm ↑ Summary DBIC/Resource/HAL/Role/SetWritable.pm »
1 package WebAPI::DBIC::Resource::ActiveModel::Role::SetWritable;
2 25 $WebAPI::DBIC::Resource::ActiveModel::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 '_build_content_types_accepted';
11 25 requires 'render_item_into_body';
12 25 requires 'decode_json';
13 25 requires 'set';
14 25 requires 'prefetch';
15  
16  
17 11 ▶around '_build_content_types_accepted' => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
18 11 my $orig = shift;
19 11 my $self = shift;
20 11 my $types = $self->$orig();
21 11 unshift @$types, { 'application/json' => 'from_activemodel_json' };
22 11 return $types;
23 25 };
24  
25  
26 0 ▶sub from_activemodel_json {
Subroutine from_activemodel_json: not called CC=1 SCAR=6.9
Pod undocumented
27 0 my $self = shift;
28 0 my $item = $self->create_resources_from_activemodel( $self->decode_json($self->request->content) );
29 0 return $self->item($item);
30 }
31  
32  
33 0 ▶sub create_resources_from_activemodel { # XXX unify with create_resource in SetWritable, like ItemWritable?
Subroutine create_resources_from_activemodel: not called CC=1 SCAR=6.9
Pod undocumented
34 0 my ($self, $activemodel) = @_;
35 0 my $item;
36  
37 0 my $schema = $self->set->result_source->schema;
38 # XXX perhaps the transaction wrapper belongs higher in the stack
39 # but it has to be below the auth layer which switches schemas
40 0 ▶ $schema->txn_do(sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
41  
42 0 $item = $self->_create_embedded_resources_from_activemodel($activemodel, $self->set->result_class);
43  
44 # resync with what's (now) in the db to pick up defaulted fields etc
45 0 $item->discard_changes();
46  
47 # called here because create_path() is too late for Web::Machine
48 # and we need it to happen inside the transaction for rollback=1 to work
49 $self->render_item_into_body(item => $item, prefetch => $self->prefetch)
50 0 ▶ if grep {defined $_->{self}} @{$self->prefetch||[]};
Branch: 1 branch
BranchTrueFalseTotal
if grep {defined $_->{"self"};} @{$self->prefetch or [];} 0 0 0
Condition0%0/2
$self->prefetch || []
l!l
00
MC/DC0%0/1
$self->prefetch || []
$self->prefetch
Truth table0%0/2
A
A= $self->prefetch
Aresult
11
00
51  
52 0 ▶ $schema->txn_rollback if $self->param('rollback'); # XXX
Branch: 1 branch
BranchTrueFalseTotal
if $self->param("rollback") 0 0 0
53 0 });
54  
55 0 return $item;
56 }
57  
58  
59 0 ▶sub _create_embedded_resources_from_activemodel {
Subroutine _create_embedded_resources_from_activemodel: not called CC=1 SCAR=6.9
60 0 my ($self, $activemodel, $result_class) = @_;
61  
62 0 return $self->set->result_source->schema->resultset($result_class)->create($activemodel);
63 }
64  
65 25 1;
66  
67 __END__
« DBIC/Resource/Role/SetInvoke.pm ↑ Summary DBIC/Resource/HAL/Role/SetWritable.pm »