| 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 | sub find_root { | ||||||||||||||||||||||||||||||||
| 18 | 14 | ▶ | my $current = $_[0]; | ||||||||||||||||||||||||||||||
|
Subroutine
find_root: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 19 | 14 | ▶ | $current = $current->parent until $current->is_root; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 20 | 14 | return $current; | |||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | sub raise_error { | ||||||||||||||||||||||||||||||||
| 24 | 7 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
raise_error: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | =pod | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | PONAPI::Document::Builder - document builder role | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | version 0.001001 | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | =head1 AUTHORS | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | =over 4 | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | =item * | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | Mickey Nasriachi <mickey@cpan.org> | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | =item * | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | Stevan Little <stevan@cpan.org> | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | =item * | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | Brian Fraser <hugmeir@cpan.org> | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | =back | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | This software is copyright (c) 2016 by Mickey Nasriachi, Stevan Little, Brian Fraser. | ||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 94 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||
| 96 | =cut | ||||||||||||||||||||||||||||||||