| 1 | # ABSTRACT: document builder role | ||||||||||||||||||||||||||||||||
| 2 | package PONAPI::Document::Builder; | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 28 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 28 | requires 'build'; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 28 | has parent => ( | |||||||||||||||||||||||||||||||
| 9 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 10 | does => 'PONAPI::Document::Builder', | ||||||||||||||||||||||||||||||||
| 11 | predicate => 'has_parent', | ||||||||||||||||||||||||||||||||
| 12 | weak_ref => 1, | ||||||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 29 | ▶ | sub is_root { ! $_[0]->has_parent } | ||||||||||||||||||||||||||||||
|
Subroutine
is_root: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | 14 | ▶ | sub find_root { | ||||||||||||||||||||||||||||||
|
Subroutine
find_root: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 18 | 14 | my $current = $_[0]; | |||||||||||||||||||||||||||||||
| 19 | 14 | ▶ | $current = $current->parent until $current->is_root; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 20 | 14 | return $current; | |||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | sub raise_error { | ||||||||||||||||||||||||||||||
|
Subroutine
raise_error: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 24 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||
| 25 | 7 | my $status = shift; | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | # XXX: | ||||||||||||||||||||||||||||||||
| 28 | # we could check the args here and look for | ||||||||||||||||||||||||||||||||
| 29 | # a `level` key which would tell us if we | ||||||||||||||||||||||||||||||||
| 30 | # should throw an exception (immediate, fatal error) | ||||||||||||||||||||||||||||||||
| 31 | # or we should just stash the error and continue. | ||||||||||||||||||||||||||||||||
| 32 | # It might get funky, but it would be nice to | ||||||||||||||||||||||||||||||||
| 33 | # unify some error handling, maybe, perhaps | ||||||||||||||||||||||||||||||||
| 34 | # I am not sure. | ||||||||||||||||||||||||||||||||
| 35 | # - SL | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 7 | $self->find_root->errors_builder->add_error( @_, status => $status ); | |||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||
| 39 | # set given status, on multiple errors use 500/400 | ||||||||||||||||||||||||||||||||
| 40 | 7 | my $st = $status; | |||||||||||||||||||||||||||||||
| 41 | 7 | ▶ | if ( $self->has_errors > 1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | 5 | ▶ | if ( $self->status >= 500 or $status >= 500 ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$self->status >= 500 or $status >= 500
MC/DC100%2/2
$self->status >= 500 or $status >= 500
$self->status >= 500
$status >= 500
Truth table100%3/3
A or B
A= $self->status >= 500B= $status >= 500
| |||||||||||||||||||||||||||||||||
| 43 | 2 | $st = 500; | |||||||||||||||||||||||||||||||
| 44 | ▶ | } elsif ( $self->status >= 400 or $status >= 400 ) { | |||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->status >= 400 or $status >= 400
MC/DC100%2/2
$self->status >= 400 or $status >= 400
$self->status >= 400
$status >= 400
Truth table100%3/3
A or B
A= $self->status >= 400B= $status >= 400
| |||||||||||||||||||||||||||||||||
| 45 | 2 | $st = 400; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | 7 | $self->set_status($st); | |||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | # we don't return value to allow condition | ||||||||||||||||||||||||||||||||
| 51 | # check when returned from validation methods | ||||||||||||||||||||||||||||||||
| 52 | 7 | return; | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 28 | ▶ | no Moose::Role; 1; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||||||||||||||