Document/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
« Document/Builder/Resource.pm ↑ Summary Document/Builder/Relationship.pm »
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
BranchTrueFalseTotal
$current->is_root or do { $current = $current->parent } 11 14 25
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
BranchTrueFalseTotal
if ($self->has_errors > 1) 5 2 7
42 5 ▶ if ( $self->status >= 500 or $status >= 500 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->status >= 500 or $status >= 500) { } 2 3 5
elsif ($self->status >= 400 or $status >= 400) { } 2 1 3
Condition100%3/3
$self->status >= 500 or $status >= 500
l!l&&r!l&&!r
113
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
111
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 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
« Document/Builder/Resource.pm ↑ Summary Document/Builder/Relationship.pm »