File Coverage

blib/lib/PONAPI/Builder.pm
Criterion Covered Total %
statement 20 20 100.0
branch 6 6 100.0
condition 6 6 100.0
subroutine 5 5 100.0
pod 0 3 0.0
total 37 40 92.5


line stmt bran cond sub pod time code
1             # ABSTRACT: document builder role
2             package PONAPI::Builder;
3              
4 36     36   50532 use Moose::Role;
  36         166829  
  36         158  
5              
6             requires 'build';
7              
8             has parent => (
9             is => 'ro',
10             does => 'PONAPI::Builder',
11             predicate => 'has_parent',
12             weak_ref => 1,
13             );
14              
15 1196     1196 0 50394 sub is_root { ! $_[0]->has_parent }
16              
17             sub find_root {
18 531     531 0 852 my $current = $_[0];
19 531         1522 $current = $current->parent until $current->is_root;
20 531         17573 return $current;
21             }
22              
23             sub raise_error {
24 112     112 0 3440 my $self = shift;
25 112         163 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         327 $self->find_root->errors_builder->add_error( @_, status => $status );
38              
39             # set given status, on multiple errors use 500/400
40 112         192 my $st = $status;
41 112 100       407 if ( $self->has_errors > 1 ) {
42 14 100 100     521 if ( $self->status >= 500 or $status >= 500 ) {
    100 100        
43 2         5 $st = 500;
44             } elsif ( $self->status >= 400 or $status >= 400 ) {
45 11         20 $st = 400;
46             }
47             }
48 112         4646 $self->set_status($st);
49              
50             # we don't return value to allow condition
51             # check when returned from validation methods
52 112         328 return;
53             }
54              
55 36     36   203788 no Moose::Role; 1;
  36         80  
  36         240  
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.002006
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