blib/lib/Net/OATH/Server/Lite/Error.pm

filter: Statementstmt 95.4% 21 / 22 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 50.0% 1 / 2 totaltotal 90.6% 29 / 32 SCAR 6.9
CC
2
Cov
92%
new
2.1
BEGIN
1.0
BEGIN
1.0
CRAP 2.0
« blib/lib/Net/OATH/Server/Lite.pm ↑ Summary blib/lib/Net/OATH/Server/Lite/DataHandler.pm »
1 package Net::OATH::Server::Lite::Error;
2 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use parent 'Class::Accessor::Fast';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use Params::Validate qw(SCALAR);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Net::OATH::Server::Lite::Error - Error class of Lite Server
11  
12 =head1 SYNOPSIS
13  
14 use Net::OATH::Server::Lite::Error;
15  
16 # default error
17 # HTTP/1.1 400 Bad Request
18 # Content-Type: application/json;charset=UTF-8
19 # Cache-Control: no-store
20 # Pragma: no-cache
21 #
22 # {
23 # "error":"invalid_request"
24 # }
25 Net::OATH::Server::Lite::Error->throw() if ...
26  
27 # custom error
28 # HTTP/1.1 404 Not Found
29 # Content-Type: application/json;charset=UTF-8
30 # Cache-Control: no-store
31 # Pragma: no-cache
32 #
33 # {
34 # "error":"invalid_request",
35 # "error_description":"invalid id"
36 # }
37 Net::OATH::Server::Lite::Error->throw(
38 code => 404,
39 description => q{invalid id},
40 ) if ...
41  
42 =cut
43  
44 6 __PACKAGE__->mk_accessors(qw(
45 code
46 error
47 description
48 ));
49  
50 sub new {
51 26 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=7.2
Pod documented
52 26 ▶ my @args = @_ == 1 ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 26 26
53 26 my %params = Params::Validate::validate_with(
54 params => \@args,
55 spec => {
56 code => {
57 type => SCALAR,
58 default => 400,
59 optional => 1,
60 },
61 error => {
62 type => SCALAR,
63 default => q{invalid_request},
64 optional => 1,
65 },
66 description => {
67 type => SCALAR,
68 default => q{},
69 optional => 1,
70 },
71 },
72 allow_extra => 0,
73 );
74  
75 26 my $self = bless \%params, $class;
76  
77 # TODO: more varidation
78
79 26 return $self;
80 }
81  
82 sub throw {
83 24 ▶ my ($class, %args) = @_;
Subroutine throw: called CC=1 SCAR=0.0
Pod undocumented
84 24 die $class->new(%args);
85 }
86  
87 6 1;
« blib/lib/Net/OATH/Server/Lite.pm ↑ Summary blib/lib/Net/OATH/Server/Lite/DataHandler.pm »