blib/lib/BZ/Client/Exception.pm

filter: Statementstmt 40.0% 8 / 20 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 28.5% 2 / 7 Podpod 100% 5 / 5 totaltotal 40.5% 15 / 37 CC 2 SCAR 10.1
CC
2
Cov
35%
new
6.0
throw
2.0
message
2.0
CRAP 2.8
« blib/lib/BZ/Client/Group.pm ↑ Summary blib/lib/BZ/Client/Classification.pm »
1 #!/bin/false
2 # PODNAME: BZ::Client::Exception
3 # ABSTRACT: Exception class thrown by BZ::Client in case of errors.
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 package BZ::Client::Exception;
9 1 $BZ::Client::Exception::VERSION = '4.4001';
10  
11 sub throw {
12 0 ▶ my $class = shift;
Subroutine throw: not called CC=1 SCAR=6.9
Pod documented
13 0 die $class->new(@_)
14 }
15  
16 sub new {
17 0 ▶ my $class = shift;
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
18 0 my $self = { @_ };
19 0 ▶ bless($self, ref($class) || $class);
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
20 0 return $self
21 }
22  
23 sub message {
24 0 ▶ my $self = shift;
Subroutine message: not called CC=1 SCAR=6.9
Pod documented
25 0 return $self->{'message'}
26 }
27  
28 sub xmlrpc_code {
29 0 ▶ my $self = shift;
Subroutine xmlrpc_code: not called CC=1 SCAR=6.9
Pod documented
30 0 return $self->{'xmlrpc_code'}
31 }
32  
33 sub http_code {
34 0 ▶ my $self = shift;
Subroutine http_code: not called CC=1 SCAR=6.9
Pod documented
35 0 return $self->{'http_code'}
36 }
37  
38 1 1;
39  
40 __END__
41  
42 =pod
43  
44 =encoding UTF-8
45  
46 =head1 NAME
47  
48 BZ::Client::Exception - Exception class thrown by BZ::Client in case of errors.
49  
50 =head1 VERSION
51  
52 version 4.4001
53  
54 =head1 SYNOPSIS
55  
56 BZ::Client does not return error codes or do similar stuff.
57 Instead, it throws instances of BZ::Client::Exception.
58  
59 my $exception = BZ::Client::Exception->new( message => $message,
60 http_code => $httpCode,
61 xmlrpc_code => $xmlrpcCode );
62  
63 BZ::Client::Exception->throw( message => $message,
64 http_code => $httpCode,
65 xmlrpc_code => $xmlrpcCode );
66  
67 =head1 METHODS
68  
69 =head2 new
70  
71 Creates the exception object
72  
73 =head2 throw
74  
75 Creates the exception object then dies, so make sure you catch it!
76  
77 =head2 message
78  
79 Returns the error message text
80  
81 =head2 xmlrpc_code
82  
83 Returns the error code from XMLRPC
84  
85 =head2 http_code
86  
87 Returns the http code (200, 404, etc)
88  
89 =head1 EXAMPLE
90  
91 Here are two examples. The first uses Perl's inbuilt eval() function, the
92 second uses the Try::Tiny module. Further alternatives exist and may be
93 perfectly good options if they suit you.
94  
95 =head2 eval
96  
97 use BZ::Client;
98 use BZ::Client::Bug::Attachment;
99 use v5.10;
100  
101 my $client = BZ::Client->new( %etc );
102  
103 eval {
104 my $att = BZ::Client::Bug::Attachment->get($client, { ids => 30505 });
105 };
106  
107 if ($@) {
108 say 'An Error Occured';
109 say 'Message: ', $@->message();
110 say 'HTTP Code: ', $@->http_code() if $@->http_code();
111 say 'XMLrpc Code: ', $@->xmlrpc_code() if $@->xmlrpc_code();
112 };
113  
114 =head2 Try::Tiny
115  
116 use BZ::Client;
117 use BZ::Client::Bug::Attachment;
118 use Try::Tiny;
119 use v5.10;
120  
121 my $client = BZ::Client->new( %etc );
122  
123 try {
124 my $att = BZ::Client::Bug::Attachment->get($client, { ids => 30505 });
125 }
126  
127 catch {
128 say 'An Error Occured';
129 say 'Message: ', $_->message();
130 say 'HTTP Code: ', $_->http_code() if $_->http_code();
131 say 'XMLrpc Code: ', $_->xmlrpc_code() if $_->xmlrpc_code();
132 };
133  
134 =head1 SEE ALSO
135  
136 L<BZ::Client>
137  
138 =head1 AUTHORS
139  
140 =over 4
141  
142 =item *
143  
144 Dean Hamstead <dean@bytefoundry.com.au>
145  
146 =item *
147  
148 Jochen Wiedmann <jochen.wiedmann@gmail.com>
149  
150 =back
151  
152 =head1 COPYRIGHT AND LICENSE
153  
154 This software is copyright (c) 2017 by Dean Hamstad.
155  
156 This is free software; you can redistribute it and/or modify it under
157 the same terms as the Perl 5 programming language system itself.
158  
159 =cut
« blib/lib/BZ/Client/Group.pm ↑ Summary blib/lib/BZ/Client/Classification.pm »