PONAPI/Builder.pm

filter: Statementstmt 100% 23 / 23 Branchbran 100% 8 / 8 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 3 totaltotal 93.8% 46 / 49 CC 7 SCAR 13.6
CC
7
Cov
100%
raise_error
6.0
find_root
2.0
BEGIN
1.0
CRAP 3.9
« PONAPI/DAO/Request/RetrieveRelationships.pm ↑ Summary PONAPI/Utils/Names.pm »
1 # ABSTRACT: document builder role
2 package PONAPI::Builder;
3  
4 36 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 36 requires 'build';
7  
8 36 has parent => (
9 is => 'ro',
10 does => 'PONAPI::Builder',
11 predicate => 'has_parent',
12 weak_ref => 1,
13 );
14  
15 1196 ▶sub is_root { ! $_[0]->has_parent }
Subroutine is_root: called CC=1 SCAR=0.0
Pod undocumented
16  
17 sub find_root {
18 531 ▶ my $current = $_[0];
Subroutine find_root: called CC=2 SCAR=6.9
Pod undocumented
19 531 ▶ $current = $current->parent until $current->is_root;
Branch: 1 branch
BranchTrueFalseTotal
$current->is_root or do { $current = $current->parent } 661 531 1192
20 531 return $current;
21 }
22  
23 sub raise_error {
24 112 ▶ my $self = shift;
Subroutine raise_error: called CC=6 SCAR=17.9
Pod undocumented
25 112 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 112 $self->find_root->errors_builder->add_error( @_, status => $status );
38  
39 # set given status, on multiple errors use 500/400
40 112 my $st = $status;
41 112 ▶ if ( $self->has_errors > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_errors > 1) 14 98 112
42 14 ▶ if ( $self->status >= 500 or $status >= 500 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->status >= 500 or $status >= 500) { } 2 12 14
elsif ($self->status >= 400 or $status >= 400) { } 11 1 12
Condition100%3/3
$self->status >= 500 or $status >= 500
l!l&&r!l&&!r
1112
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
ABresult
1X1
011
000
43 2 $st = 500;
44 ▶ } elsif ( $self->status >= 400 or $status >= 400 ) {
Condition100%3/3
$self->status >= 400 or $status >= 400
l!l&&r!l&&!r
1011
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
ABresult
1X1
011
000
45 11 $st = 400;
46 }
47 }
48 112 $self->set_status($st);
49  
50 # we don't return value to allow condition
51 # check when returned from validation methods
52 112 return;
53 }
54  
55 36 ▶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::Builder - document builder role
66  
67 =head1 VERSION
68  
69 version 0.002012
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
« PONAPI/DAO/Request/RetrieveRelationships.pm ↑ Summary PONAPI/Utils/Names.pm »